1 Chronicles 21: 1, 5-14 (RSV) Satan stood up against Israel, and incited David to number Israel. . . .  And Jo’ab gave the sum of the numbering of the people to David. . . .  But he did not include Levi and Benjamin in the numbering, for the king’s command was abhorrent to Jo’ab.  But God was displeased with this thing, and he smote Israel.  And David said to God, “I have sinned greatly in that I have done this thing. But now, I pray thee, take away the iniquity of thy servant; for I have done very foolishly.”  And the LORD spoke to Gad, David’s seer, saying,  “Go and say to David, `Thus says the LORD, Three things I offer you; choose one of them, that I may do it to you.'”  So Gad came to David and said to him, “Thus says the LORD, `Take which you will:  either three years of famine; or three months of devastation by your foes, while the sword of your enemies overtakes you; or else three days of the sword of the LORD, pestilence upon the land, and the angel of the LORD destroying throughout all the territory of Israel.’ Now decide what answer I shall return to him who sent me.”  Then David said to Gad, “I am in great distress; let me fall into the hand of the LORD, for his mercy is very great; but let me not fall into the hand of man.”  So the LORD sent a pestilence upon Israel; and there fell seventy thousand men of Israel.
At first glance, this does seem to be a very strange passage indeed, and quite difficult to understand, in light of the biblical teaching that God is loving and merciful and just in His judgments. It seems to pose a challenge to those notions. God appears to be capricious, unfair, arbitrary, and unjust: judging 70,000 souls because of the sin of David. So it’s not unusual that atheists would take this and have a field day with it, because even Christians struggle with it; such as one Methodist pastor, who wrote:
God’s anger and wrath. In the Old Testament, God’s anger repeatedly burns against his people for their disobedience. At times, the punishment he dispenses seems particularly harsh, unjust, and disproportionate. Let’s consider just one example.
In 2 Samuel 24, we find that King David decided to take a census of the men of fighting age. The prophet Gad was sent to David to announce God’s displeasure with the taking of the census. The punishment for David’s sin: “The Lord sent a pestilence on Israel from that morning until the appointed time; and seventy thousand of the people died” (2 Samuel 24:15). David makes a decision that does not please God, and God kills 70,000 Israelites for it? How could this action ever be reconciled with a God of mercy, compassion, justice, and love?
An atheist site expresses its disdain in the title of its article devoted to this: “God killed 70,000 because David did a census that God (or Satan) told him to do.”
But I think I have a plausible and satisfactory explanation, that makes sense of the seeming oddities or mysteries regarding God’s judgment. It’s arrived at particularly by examining the cross reference to the passage: 2 Samuel, chapter 24, more closely.
2 Samuel 24:1 Again the anger of the LORD was kindled against Israel, and he incited David against them, saying, “Go, number Israel and Judah.”
As for the question of Satan seeming to be the instigator of this in one passage (1 Chr 21:1), but God being the cause in the parallel passage (2 Sam 24:1), see my explanation elsewhere. But why was God angry; why did He want to judge Israel? Well, it was actually only one tribe of Israel that deserved His wrath:
2 Samuel 24:15 So the LORD sent a pestilence upon Israel from the morning until the appointed time; and there died of the people from Dan to Beer-sheba seventy thousand men. (in 1 Chronicles 21 it doesn’t specify the tribe of Dan).
What sins did this tribe commit, then, to receive such a harsh judgment? Well, we know several things from Scripture. Dan abandoned God and turned to idolatry before the time of David:
Judges 18:30-31 And the Danites set up the graven image for themselves; and Jonathan the son of Gershom, son of Moses, and his sons were priests to the tribe of the Danites until the day of the captivity of the land.  So they set up Micah’s graven image which he made, as long as the house of God was at Shiloh.
Its downfall was predicted far earlier, in fact:
Genesis 49:17 Dan shall be a serpent in the way, a viper by the path, that bites the horse’s heels so that his rider falls backward.
The tribe of Dan is not listed among the tribes names in Revelation 7:4-8. The reasonable explanation, from what we know in Scripture, is that it was due to this described idolatry. Their captivity under the Assyrians took place in 722 B.C. (1 Ki 12:28-30; 2 Ki 10:29). That was some 240 years after King David, but Judges 18:30 tells us that they were in bondage to idolatry the entire time. Hence, it is perfectly plausible to posit that this is why they were judged during the time of David (70,000 slain).
Idolatry was one of the gravest sins, and it is repeatedly condemned throughout the Old Testament, with warnings of impending judgment, failing repentance. For example:
2 Chronicles 24:18-20 And they forsook the house of the LORD, the God of their fathers, and served the Ashe’rim and the idols. And wrath came upon Judah and Jerusalem for this their guilt.  Yet he sent prophets among them to bring them back to the LORD; these testified against them, but they would not give heed.  Then the Spirit of God took possession of Zechari’ah the son of Jehoi’ada the priest; and he stood above the people, and said to them, “Thus says God, `Why do you transgress the commandments of the LORD, so that you cannot prosper? Because you have forsaken the LORD, he has forsaken you.'”
Ezekiel 20:18-19 And I said to their children in the wilderness, Do not walk in the statutes of your fathers, nor observe their ordinances, nor defile yourselves with their idols.  I the LORD am your God; walk in my statutes, and be careful to observe my ordinances,
Ezekiel 36:18-19 So I poured out my wrath upon them for the blood which they had shed in the land, for the idols with which they had defiled it.  I scattered them among the nations, and they were dispersed through the countries; in accordance with their conduct and their deeds I judged them.
God judges target groups of people who are particularly evil (or else entire countries that have become evil). They are accountable for their own sins, as the Bible teaches:
2 Kings 14:6 But he did not put to death the children of the murderers; according to what is written in the book of the law of Moses, where the LORD commanded, “The fathers shall not be put to death for the children, or the children be put to death for the fathers; but every man shall die for his own sin.” (cf. parallel passage 2 Chr 25:4)
Jeremiah 31:30 But every one shall die for his own sin . . .
2 Maccabees 7:32 For we are suffering because of our own sins.
1 Peter 1:17 . . . who judges each one impartially according to his deeds . . .
Thus, in this particular instance, it was the tribe of Dan that was His specific target, because it had given itself up wholly to idolatry; hence, were more than ripe for judgment by the time of King David.
Lastly, it might be objected that the phrase “from Dan to Beersheba” referred to the entirety of Israel (as opposed to the tribe of Dan only). But we know that the original region of the tribe of Dan was west of Jerusalem. The Encyclopaedia Britannica article (“Dan”) confirms this:
The portion assigned to the tribe of Dan was a region west of Jerusalem. At least part of the tribe later moved to the extreme northeast and took the city of Laish, renaming it Dan. As the northernmost Israelite city it became a point of reference in the familiar phrase “from Dan to Beersheba.” [my italics]
When God was judging in this instance, in fact, He did not judge “throughout all the territory of Israel” (1 Chr 21:12). 70,000 were already judged when the angel of God came to Jerusalem (that is, the region east of the tribe of Dan’s area; “David lifted his eyes and saw the angel of the LORD standing between earth and heaven, and in his hand a drawn sword stretched out over Jerusalem”: 1 Chr 21:16), at which point God in His mercy, and apparently in part due to the intercession of David and his elders (1 Chr 21:16-17), stopped the frightful judgment (2 Sam 24:16; 1 Chr 21:15).
Photo credit: Sacrifice of Jeroboam [i.e., to idols] (1641), by Claes Moeyaert (1591-1655) [public domain / Wikimedia Commons]