In II Samuel 24:1-2, it was written that David commanded Joab to take a census of Israel. After the census was taken, in II Samuel 24:10, David knew that he had sinned and God sends a pestilence upon Israel as a consequence. Why did God consider David commanding a census of Israel sin? And what does Joab's response to David in II Samuel 24:3 and I Chronicles 21:3 mean?
Your question is one that has been debated for centuries. What we do know is that at the time of the census, there was no need. Israel wasn't preparing for or involved in a war at the time. Thus, most conclude that David did this out of pride.
Joab argued against the census because it indicated a lack of trust in God. "And Joab answered, "May the LORD make His people a hundred times more than they are. But, my lord the king, are they not all my lord's servants? Why then does my lord require this thing? Why should he be a cause of guilt in Israel?" " (I Chronicles 21:3; see also II Samuel 24:3). With God on their side, the people could be 100 times more numerous and still not make a difference. Joab is saying the numbers don't matter, and he hopes David lives to see the day when Israel's population grows a hundredfold. Joab saw numbering the Israelites as not trusting God.
There was a law that said that if a census is taken, it had to be accompanied by a census tax. "Then the LORD spoke to Moses, saying: "When you take the census of the children of Israel for their number, then every man shall give a ransom for himself to the LORD, when you number them, that there may be no plague among them when you number them. This is what everyone among those who are numbered shall give: half a shekel according to the shekel of the sanctuary (a shekel is twenty gerahs). The half-shekel shall be an offering to the LORD. Everyone included among those who are numbered, from twenty years old and above, shall give an offering to the LORD. The rich shall not give more and the poor shall not give less than half a shekel, when you give an offering to the LORD, to make atonement for yourselves. And you shall take the atonement money of the children of Israel, and shall appoint it for the service of the tabernacle of meeting, that it may be a memorial for the children of Israel before the LORD, to make atonement for yourselves" " (Exodus 30:11-16). David didn't order the tax, just the census. Notice that when people were numbered, God required the people to redeem themselves and if they didn't, there would be a plague. God kept His word, He sent a plague on Israel because of the census. That plague, by the way, ruined the count that was just made.
Having a tax associated with the census was a discouragement from taking census often, or for no particular purpose. God wanted Israel to trust in Him. However many of them there were, they would always be enough. Numbering the people changed matters from relying on God to relying on men. "Some trust in chariots, and some in horses; but we will remember the name of the LORD our God" (Psalms 20:7). Decisions about whether to go to war would no longer be solely a question of right versus wrong but whether Israel is more powerful than the ones attacked. This is not how God wanted Israel to operate.