In both 2 Samuel and 1 Chronicles the story is told of David counting the military men of Israel. Exodus 30 gives some stipulations around taking a census and it requires that all give to the LORD. The census which David took must have forsaken this commandment as it explicitly lists plague as the penalty for disobedience - which they received.

In context of 1 Chronicles 19-21 we see that this came in a time of crazy wars and irrational leaders of other nations. This count was done from a position of pride and fear, not trust and faith.

Links:

202507150835