Israel has offended God, to punish them, He moves David to take a census and in the process, David himself sins against God through putting his trust in the number of fighting men that the nation now has. It is amazing how many times David sings against God but God again and again, shows him mercies, have you ever asked why? Saul did less than half of this and God rejected him.