Divine Providence #244
244. 4. Because David had taken a census of the people, a plague was sent and thousands of people died; and God did not send Gad the prophet to announce the punishment beforehand but only after the fact. Various thoughts and ruminations about this may occur to people who resolutely deny divine providence. They may ask particularly why David was not warned in advance and why the people were punished so severely for David's transgression.
The reason he was not warned in advance comes under laws of divine providence already presented, especially the two explained in 129-153, 154-174. The reason the people were punished so severely for the transgression of their king (seventy thousand were struck by the plague) had to do not with the king but with the people, since it says, "Jehovah became more angry with Israel, so he prompted David against them by saying, 'Go, number Israel and Judah'" (2 Samuel 24:1).