1 Samuel 4:1-11, especially
v10-11 So the Philistines fought, and Israel was defeated, and they fled, every man to his home. And there was a very great slaughter, for there fell of Israel thirty thousand foot soldiers. And the ark of God was captured.
The people of Israel treated the ark of the covenant as a magical item that could save them from defeat in battle. The defeat of Israel showed that this to be wrong. God chose to show his power by humiliating the Philistine god Dagon:
1 Samuel 5:1-4 When the Philistines captured the ark of God, they brought it from Ebenezer to Ashdod. (2) Then the Philistines took the ark of God and brought it into the house of Dagon and set it up beside Dagon. (3) And when the people of Ashdod rose early the next day, behold, Dagon had fallen face downward on the ground before the ark of the LORD. So they took Dagon and put him back in his place. (4) But when they rose early on the next morning, behold, Dagon had fallen face downward on the ground before the ark of the LORD, and the head of Dagon and both his hands were lying cut off on the threshold. Only the trunk of Dagon was left to him.
This prompted the Philistines to return the ark to Israel. There is no reason to question God’s action. He could have chosen to kill some or all of the Philistines, but did not. God showed his power to both Israel and the Philistines. That was enough.
Later when Israel did not respect the ark some Israelite deaths resulted. Once again there is no reason to challenge God’s action. God could have chosen a less severe response, but did not. Perhaps God held Israel more accountable because they should have known better. Whatever God’s reasons there is no reason to suppose that he should make the same decisions that we would make.