When David gave orders to number Israel, he did what the ungodly nations were in the habit of doing (Psalm xx. 7). The God of Israel had expressly forbidden trusting in numbers (1 Sam. xiv. 7; xvii. 47). God will not countenance His children putting their trust in an arm of flesh (Jer. xvii. 5). Even Joab knew it was wrong (2 Sam. xxiv. 3).
In view of the fact that, in itself, numbering of Israel was not contrary to God’s wishes (Num. i. 3, etc.), David’s sin must have been in his motive, and David knew it, in view of his admission that he had “sinned greatly” in the matter (2 Sam, xxiv. 10).