If God tells you to sin, is it still a sin? What if God tells a king to sin because he’s mad at the king’s people and he wants an excuse to punish them? That’s precisely what happens in 2 Samuel 24:1, “Again the anger of the Lord was kindled against Israel, and he incited David against them, saying, ‘Go, count the people of Israel and Judah.'” As “punishment” for the census, which God told David to take, God sends a plague that kills 70,000 Israelites. God doesn’t come off very well in this story, which may be why 1 Chronicles 21:1 edits the story to make “Satan” the one who “incited David to count the people of Israel.” This puzzling story is one of many examples of progressive revelation that Derek Flood addresses in his new book Disarming Scripture.
So why was it a sin to count the Israelites in the first place? Exodus 30:11-12 is the only passage in Torah that addresses census-taking: “When you take a census of the Israelites to register them, at registration all of them shall give a ransom for their lives to the Lord, so that no plague may come upon them for being registered. This is what each one who is registered shall give: half a shekel according to the shekel of the sanctuary (the shekel is twenty gerahs), half a shekel as an offering to the Lord.”
So there’s a particular protocol for census-taking. But Exodus 30 implies that census-taking in and of itself is a routine, Biblically-sanctioned practice. It seems that the Torah establishes the census as a means for collecting a temple tax: “You shall take the atonement money from the Israelites and shall designate it for the service of the tent of meeting.”
There’s no indication in the 2 Samuel 24 that David violated this protocol. The way that David took the census is not problematized by the text, but rather the mere fact that he took a census: “David was stricken to the heart because he had numbered the people.” So it’s not that David didn’t collect a temple tax as part of the census that makes David “stricken to the heart,” but simply the fact that “he had numbered the people.” The trouble is there’s nothing in the Torah which says “numbering the people” is wrong in and of itself. So whatever Israelite tradition had condemned “numbering the people” did not make it into the final cut of the Bible.
Of course that’s not the only problem. If God really does command people to commit sins to give him an excuse for punishing them, that’s about as dirty as when the riot police form a circle around a group of protesters, order them to disperse, and then arrest them for being physically unable to comply with their order (which happened at an anti-globalization protest in DC in 2001). But God’s always right just like the police are always right because he’s God, right?
Derek Flood sees a different possible explanation here:
When we read passages that ascribe evil to God in the Old Testament, we need to recognize that this is written from the viewpoint of a people who had no concept of the devil, and who consequently attributed injury, deception, and suffering to the hand of God. 
What if this story came about because King David took a census, and soon afterwards, a mysterious epidemic swept through Israel? In a pre-scientific world, all the bad natural things that happened — droughts, floods, earthquakes, diseases, etc — were explained as expressions of God’s anger. As Israel’s understanding of God evolved, there came to be an understanding of an evil adversary within the universe who causes suffering to God’s people against God’s will. As the book of Job explains by introducing the character of Satan into the equation, not every misfortune in life is a product of God’s judgment against sin. 1 Chronicles was written after Satan had become part of the possible explanation for natural tragedies. Thus, 1 Chronicles makes Satan the instigator beneath David’s census instead of God. It’s an example of revisionism occurring inside the canon of scripture.
So which account of David’s census is true? 2 Samuel 24 or 1 Chronicles 21? Did God or Satan order the census? This is checkmate for Biblical inerrancy. Both passages purport to be talking about the exact same historical event, and they contradict each other on a major detail. One fundamentalist tries to dodge the bullet by saying that “this discrepancy can be explained by the understanding that sometimes God sovereignly permits Satan to act in order to achieve His purposes.” The problem is that 2 Samuel 24 explicitly puts the command to take a census in the mouth of God. If there were a version of the Bible that “red-lettered” direct quotes from God in the Old Testament just like Jesus’ direct quotes in the New Testament, then “Go, count the people of Israel and Judah” would be a red-letter phrase.
Thank God the Bible never claims to be historically inerrant, only God-breathed and useful! If we trust 2 Timothy 3:16 that “all scripture is inspired by God and is useful for teaching, for reproof, for correction, and for training in righteousness,” then instead of fretting over whether 2 Samuel 24 is an accurate depiction of God’s character, we will look for something in the passage that is useful for teaching, reproof, correction, or training in righteousness. All that the Bible guarantees about 2 Samuel 24 is that God has a teaching purpose for that passage even if its author misattributed God’s wrath to a lethal epidemic that coincided with David’s census.
Derek Flood’s Disarming Scripture proposes a way of reading scripture in which we stop worrying about defending its historical accuracy or having an easy explanation for the troubling depictions of God’s character in parts of the Old Testament. Jesus is the uniquely perfect self-revelation of God so he is the one we should look to when trying to understand God’s character. But every verse in the Bible has something to teach us, even the Old Testament passages that make God look like an emotionally insecure, petulant bully.
It doesn’t matter whether God or Satan ordered David to take a census. What matters is how this story can help us in our discipleship journeys today. Perhaps we need to stop obsessively counting our money, our friends, and our achievements. Perhaps the lesson comes in David’s insight that it’s better to “fall into the hand of the Lord, for his mercy is great [than to]… fall into human hands” (2 Samuel 24:14). This story does not need to be an accurate depiction of God’s character to be packed with useful, God-breathed truth that the Holy Spirit can reveal to us.