Shela (Tanis Aseres HaDibros, Torah Ohr 4:44) This that it says in Moed Koton (28a) that just as Yom Kippur atones so does the death of tzadikim atone. In other words just as Yom Kippur does not atone without repentance so too the death of a tzadik only atones for those who repent. But possibly it is teaching that both Yom Kippur and the death of a tzadik atone with and without repentance but that is not so as we learned from previously regarding the bones of Shaul. Thus we learn here that only with repentance does the death of a tzadik and Yom Kippur atone. This is reinforced by the statement : Why is the death of Miriam adjacent to the section of the Red Heifer in the Torah? Just as the red Heifer atones so does the death of tzadikim and that is only for those who repented.
Bamidbar Rabbah (19:08) A certain idolater asked Rabban Yoḥanan ben Zakai: ‘These actions that you perform seem to be a type of sorcery. You bring a heifer, burn it, crush it, and take its ashes. One of you becomes impure from a corpse, one sprinkles upon him two or three drops, and you say to him: You are purified.’ He said to him: ‘Has a spirit of insanity never entered you?’ He said to him: ‘No.’ ‘Have you seen a person into whom a spirit of insanity has entered?’ He said to him: ‘Yes.’ He said to him: ‘And what do you do to him?’ He said to him: ‘We bring roots, smoke them beneath him, and sprinkle water on it, and it flees.’ He said to him: ‘Let your ears hear what you express from your mouth. The same is true of this spirit, this spirit of impurity, as it is written: “I will remove the prophets and the spirit of impurity from the land” (Zechariah 13:2). We sprinkle upon it the water of sprinkling, and it flees.’After he left, his students said to him: ‘You rebuffed this one with a reed. What do you say to us?’ He said to them: ‘As you live, it is not the corpse that impurifies, and it is not the water that purifies. Rather, the Holy One blessed be He said: I instituted a statute, issued a decree; you are not permitted to violate My decree, as it is written: “This is the statute of the Torah.”’
Moed Koton (28a) Wherefore is the account of Miriam's death placed next to the laws of the red heifer? To inform you that even as the red heifer afforded atonement by the ritual use of its ashes, so does the death of tie righteous afford atonement for the living they have left behind.
Moed Koton (28a) Wherefore is the account of Aaron's death closely followed by the account of the disposal of the priestly vestments? To inform you that just as the priest's vestments were means to effect atonement so is the death of the righteousconducive to procuring atonement.