God was feeling angry at his people, and needed an excuse to punish them. So he told David to take a census of Israel.1 David’s commander Joab thought God’s idea was repulsive for some reason, but he helped David count the Israelites anyway.
After taking the census, David decided that Joab was right, that what he had done was foolish and sinful, and God agreed. God sent a prophet to ask David how he would like to be punished for obeying God. David didn’t fear God as much as he feared men, so he said he would prefer God to punish him himself, rather than sending David’s enemies to punish him.
So God sent a plague that killed tens of thousands of Israelites. David pointed out that God was punishing the wrong people, and suggested punishing him instead. But the prophet said God wouldn’t stop killing innocent people until David made him a sacrifice. Someone offered to give David some free oxen to sacrifice, but unlike Abraham, David realized that a sacrifice that doesn’t cost you anything isn’t a real sacrifice. So David bought the oxen and sacrificed them, and then God was willing to stop murdering his people.
The moral of the story
Don’t live in a country governed by people who obey God, or God might kill you.