Question: R. Eleazar said The Holy One, blessed be, said to the angel Take a great man among them, through whose death many sins can be expiated for them. This is according to the dictum that the death of the righteous is an atonement. What is this actually refering to? What do they mean by atonement in this case?
Peretz
The atonement that the Gemara is referring to is atonement for the sin of counting the Jewish people directly, and not through the medium of the Shekalim, as the Gemara explains.
The concept that the death of the righteous is an atonement is compared by the Gemara to the destruction of the Beis ha'Mikdash, which is also an atonement for the Jewish people. In both cases, the idea is the following:
(1) When the Jews see that someone, or something, so great and holy was taken from them, it arouses in them the undeniable awareness that it happened as a result of their terrible sins (which, until now, they did not realize they were guilty of). As a result, they repent and are forgiven. (2) Furthermore, the righteous person protects the generation, and because he protects them, they are not punished for what they deserve to be punished for. Once the righteous person is taken from them, there is no more protection and the Jews begin to be punished. They then no longer feel safe and secure, the way they felt under the protection of the righteous person, and they therefore repent.
(The Magid m'Dubno gives a similar explanation on the verse, "Erase me, please, from Your book" (Shemos 34): Moshe asked that Hash-m bring him down from his greatness in order for the Jewish people not to feel secure under his protection, so that they would stop sinning and repent.)
-Mordecai