Why did God kill many people in the Old Testament, such as: "But God struck down some of the men of Beth Shemesh, putting seventy of them to death because they had looked into the ark of the LORD. The people mourned because of the heavy blow the LORD had dealt them" (I Samuel 6:19)
People have a tendency to categorize others. In a way, it makes it easier to deal with people if we can predict their responses. "Oh, he always gets angry." Or, "she'll talk your ear off if you let her." But all these classifications are really oversimplifying the personality of the person with whom we are dealing.
Not surprising, people do the same thing with God. But with God, the results are often poor because God is so vastly greater than man. There is a sermon outline on this topic called "Oversimplifying God" which discusses this very thing. People have a tendency to look at the love of God because of all the benefits it brings them, but then they ignore the justice of God.
For hundreds of years, God had told the people of Israel that He is to be treated as holy. God wasn't some casual creation of man. He and the things He had made for His worship were to be treated with the greatest of respect. Early on, two priests lost their lives because they treated God's worship in a casual manner. "Then Nadab and Abihu, the sons of Aaron, each took his censer and put fire in it, put incense on it, and offered profane fire before the LORD, which He had not commanded them. So fire went out from the LORD and devoured them, and they died before the LORD. And Moses said to Aaron, "This is what the LORD spoke, saying: 'By those who come near Me I must be regarded as holy; And before all the people I must be glorified.'" So Aaron held his peace" (Leviticus 10:1-3).
A command that God had given was that the ark of the covenant was to be treated with extra care. Only the priests were allowed to see it, and then only once a year or when the tabernacle needed to be moved. "When the camp prepares to journey, Aaron and his sons shall come, and they shall take down the covering veil and cover the ark of the Testimony with it. ... And when Aaron and his sons have finished covering the sanctuary and all the furnishings of the sanctuary when the camp is set to go, then the sons of Kohath shall come to carry them; but they shall not touch any holy thing, lest they die. These are the things in the tabernacle of meeting which the sons of Kohath are to carry. ... But they shall not go in to watch while the holy things are being covered, lest they die" (Numbers 4: 5, 10, 20). Notice that God had carefully warned Israel of the consequences of looking or touching the holy things in the tabernacle.
Therefore, when the men of Beth Shemesh saw that the ark of the covenant was returned, they did the very thing God told them not to do. They touched the ark, opened it up, and looked inside it. God said that doing such things would result in death, so He carried out the punishment that He had promised long ago.
God's ability to carry out justice is not limited to the Old Testament. A husband and wife in the early church lost their lives when they thought they could trick God. "But a certain man named Ananias, with Sapphira his wife, sold a possession. And he kept back part of the proceeds, his wife also being aware of it, and brought a certain part and laid it at the apostles' feet. But Peter said, "Ananias, why has Satan filled your heart to lie to the Holy Spirit and keep back part of the price of the land for yourself? While it remained, was it not your own? And after it was sold, was it not in your own control? Why have you conceived this thing in your heart? You have not lied to men but to God." Then Ananias, hearing these words, fell down and breathed his last. So great fear came upon all those who heard these things. And the young men arose and wrapped him up, carried him out, and buried him. Now it was about three hours later when his wife came in, not knowing what had happened. And Peter answered her, "Tell me whether you sold the land for so much?" She said, "Yes, for so much." Then Peter said to her, "How is it that you have agreed together to test the Spirit of the Lord? Look, the feet of those who have buried your husband are at the door, and they will carry you out." Then immediately she fell down at his feet and breathed her last. And the young men came in and found her dead, and carrying her out, buried her by her husband. So great fear came upon all the church and upon all who heard these things" (Acts 5:1-11).
Why are these events recorded? Because people get it into their heads that God is so loving that there is no way He would send people to an eternity in Hell. God is demonstrating that He is able and willing to carry out justice when it is needed. "Therefore consider the goodness and severity of God: on those who fell, severity; but toward you, goodness, if you continue in His goodness. Otherwise, you also will be cut off" (Romans 11:22).