The taking of a census, by David or anyone else, is not a sin of itself. The reason for doing it, however, certainly can be and is something that might be worthy of being punished for! The book of Chronicles tells us that Satan the devil, who was against ancient Israel, moved or provoked King David to count his troops.
Then Satan stood up against Israel and provoked David to number Israel. (1Chronicles 21:1).
An Active Adversary
Satan moved in spiritual warfare against the whole nation of Israel and not just the king. With his cunning ways, the devil set out to entice David to sin by numbering his army through a census, which is exactly what he did (2Samuel 24:1)!
The KJV Bible translation of 2Samuel 24:1, unfortunately, tends to give the reader the wrong impression regarding the motivation behind the census. Young's Literal Translation offers a more accurate explanation of what transpired. Samuel states, "And the anger of Jehovah addeth to burn against Israel, and an adversary [Satan] moveth David about them, saying, 'Go, number Israel and Judah'" (2Samuel 24:1).
Satan the devil moved David to disobey God. The king seemed to have been prompted by a feeling of pride and ambitious curiosity. The devil tempted, but the king went along with it and wanted to use the census as evidence to trust in himself and other humans rather than God's power. It was his vanity and the desire to exalt himself in his own mind that got David in trouble.
Anytime Satan is involved, you can be sure he intends to lead someone to sin! He put the thought in David's mind that if he knew the number of young men under his rule (meaning those fit for war) he could brag or boast how great a king he was by the size of his army! Taking a census was a common way to gauge a nation's potential strength in battle (Numbers 1:1 - 4, 19).
Joab, commander of David's army, tried to warn him not to number Israel so that he and the nation would not be punished. His wise counsel, however, went unheeded.
And David said to Joab and to the rulers of the people, "Go number Israel from Beersheba to Dan. And bring the number of them to me so that I may know."
And Joab answered, "May the Lord add to His people a hundred times, but my lord the king, are they not all my lord's servants? Why then does my lord require this thing? Why will he be a cause of trespass to Israel?" (1Chronicles 21:2 - 3).
Census Pride
Easton's Illustrated Bible Dictionary also has some interesting comments regarding this incident. It states that David acted out of pride and a desire to glorify himself. He had come to the point in his life where he was relying far more on his own strength and that of his army rather than on God.
After his sin, God told David to choose one of three ways to be punished.
And Gad came to David and said to him, "Thus says the Lord, 'Choose for yourself:
"'Either three years of famine, or three months to be swept away before your foes, while the sword of your enemies overtakes you, or else three days of the sword of the Lord, even the plague in the land, and the angel of the Lord destroying throughout all the border of Israel.'" (1Chronicles 21:11 - 12).
The first way was to have a famine throughout the land for three years. The second choice of correction was to flee from his enemies for three months. David knew what this was like, as he had many times fled from Saul and even had to flee from his son Absalom.
The third way he was offered for carrying out a census was three days of pestilence (a deadly epidemic) upon the land. The king choose to, as he put it, "fall into the hands of the Lord," which meant the pestilence. Ten of thousands died throughout Israel until the death angel was stopped just before entering Jerusalem. David pleaded for mercy and was told to build an altar to God on a particular threshing floor (2Samuel 24:16 - 18). The pestilence was thus halted.
It would be at threshing floor location on which David appeased God and stayed the death angel that another momentous event would take place! His sacrifice for taking a census took place on Mount Moriah. This is the same mount where Abraham's faith was testing through the planned sacrifice of his son Isaac (Genesis 22:2). It is also the exact spot chosen by King Solomon to build God's magnificent temple (2Chronicles 3:1).