The answer must reside in David’s motive. It seems that David was concerned with his own glory; knowing the number of his subjects gave him a feeling of pride. God however was interested only in knowing how many people He could rely upon to serve Him and to contribute to the wellbeing of the nation. Even so, the Divinely-commanded census was not a direct count: each of the people gave a half-shekel and the coins were then counted in order to produce a population statistic.
However, it was not the money as such which was important. The rich could have given the whole sum, alleviating the burden on the poor, for whom a half-shekel was not an insignificant amount. That would have defeated God’s purpose. Regardless of rank or status, each Israelite had equal value in His eyes. They were measured by their deeds, not their social or economic standing.
Does this fit in with Rashi’s interpretation, that counting half-shekels instead of human beings was in order to guard against the “evil eye”? Yes, if you take the view of Pir’kei Avot that the “good eye” is symbolic of generosity, and the “evil eye” represents meanness (Avot 2:14 etc.). A mean person gives nothing, whereas God wants everyone to be a giver, a contributor to society.