If there is no agency for sin, why was King David punished for sending people out to conduct a (forbidden) census? (Explanation of agency: The Talmud says "ein sheliach l'dvar averia," which means, practically speaking, that if you tell someone to eat non-kosher food, the sin is on the person who eats the food, not on you.)
Possibly it's an issue of hora'as sha'ah. See ... all of maseches Horayos for detailed discussion on how Beis Din handles broadcasting improper halachic rulings that cause the public to commit an aveirah.
"Ein sheliach" works potentially in two different ways - 1) divrei harav vidivrei hatalmid, and 2) Chazal not giving the capacity for shlichus in the case of an aveirah.
- Since he was operating in position of authority more so than an average individual, he was held responsible for the command. Disobeying a direct order from the king may make you Chayiv Misa - see Shmuel 1 where people disobeying Shaul are killed - most of those were considered legally justified. That being the case, people are compelled to engage in this impermissable behavior, since the alternative is dying. So "divrei harav vidivrei hatalmid, divrei mi shomin?" wouldn't shield Dovid from culpability in this case. That potentially puts Dovid in the position of machti es harabim on top of being responsible for the aveirah being committed.
- This may not be a case of shlichus anyhow - he was punished for issuing the command to count (over Yo'av's objections), not the act of counting itself. Also, the whole story is prefaced by either Hashem (in shmuel 2 24:1) or the satan (in divrei hayamim 1 21:1) inspiring Dovid to act. Dovid says he has sinned, not the navi Gad. Hashem merely gives Dovid a choice of punishments but doesn't accuse him of wrongdoing. In divrei Hayamim, it inverts the order and says Hashem was mad BECAUSE of the census, but still doesn't tell Dovid that he did wrong.
Practically speaking, since this was a punishment from Hashem, it's in His hands to determine guilt. This is clearly an exception to whatever other rules we think may apply.
David decides to take a census
II Samuel, chapter 24, records one of the most puzzling stories in the Bible. II Samuel 24:9 tells us that King David took a census that resulted in a plague that killed seventy thousand Israelites. But counting or taking a census in the Bible could be done in order to determine the availability for war, for the division of land, and for tax purposes. But what did David do wrong and why were innocent people, indeed seventy thousand of them, killed by a plague?
In the story, David orders his commanding general Joab to assemble the soldiers to tally people. The procedure ends after nine months and twenty days, when Joab returns with the count of eight hundred thousand men, along with an additional five hundred thousand from Judah as reserves which could be mobilized in a time of war. When David heard this report he immediately began to regret ever having taken the census. For the count has been made public.
What did Maimonides think
In his Guide of the Perplexed 2:48, Maimonides explains that whenever the Bible says that G-d did something, it is not that G-d actually did it but what occurred was the result of the laws of nature. Since G-d created the laws of nature, the Bible attributes the event to G-d, since G-d is the ultimate cause. If we understand the text in this way, we can posit that G-d did not really become angry (Rambam felt that G-d does not have emotions).
Why did David take the census?
David probably undertook the census to gauge how many men or to procure potential soldiers that he could muster for an anticipated battle since David engaged in many wars. For the census, David dispatched his senior officers to determine who was fit for military service. However, the census was done publicly which came to the attention of Israel’s enemies, the very nations that David was assembling forces to fight. When the enemies learned of the census they took preventative measures and mapped out the area of drafting disseminated along Israel's boarder, resulting in an ambush of David’s forces.
After the census, David lamented it was too late. There was nothing he could do but face the consequences. The world functions according to the laws of nature, and one of those laws is that every act has a consequence. Thus, the prophet Gad had three possibilities for David’s negligent behavior. David could have fought the enemy or famine might arise as what happened to Saul. The plague was the result of a great slaughter [decomposing corpses]. Alternatively, the seventy thousand men were killed in battle, a “plague.” This number would have been much smaller had the census not been publicized. After the plague, Gad told David to set an altar where the plague has stopped, as a remembrance for David not to make the same mistake twice. The phrase “David’s Heart Smote Him” is a metaphor for David’s regret since the ancients considered the heart to be the seat of wisdom.
The last chapter of the biblical book of Samuel, if taken literally describes an angry G-d pushing David, resulting in deaths of tens of thousands. This is theologically problematic. But if we read according to Maimonides’ teaching in Guide 2:48, it can be explained in a more rational manner. David was punished due to natural consequences. When David dispatched a military contingent to take a census over a nine-month period which was mistakenly publicized. We can surmise that the enemy discovered the secret, fought or ambushed David’s army, resulting in the deaths of seventy thousand men, followed by a three-day plague.