Rabbi Abba bar Abbina said: For what reason is the passage of Miriam placed next to the passage of the ashes of the heifer? It is simply to teach that just as the ashes of the heifer atone, so the death of the righteous atones. Rabbi Judan said: For what reason is the death of Aaron placed next to the breaking of the tablets? It teaches that the death of the righteous is as grievous before the Holy One as the breaking of the tablets. Rabbi Hiyya bar Abba said: The sons of Aaron died on the first of Nisan. Why does it mention their death on the Day of Atonement? It is simply to teach that, just as the Day of Atonement atones, so the death of the righteous atones. And from where is it shown that the Day of Atonement atones? As it is stated (Leviticus 16:30): "For on this day atonement shall be made for you, to cleanse you." And from where is it shown that the death of the righteous atones? As it is stated (II Samuel 21:14): "And they buried the bones of Saul... and afterward God responded to the plea for the land."
Why the Death of the Righteous Atones Like Yom Kippur
Midrash Tanchuma Buber, Achrei Mot 10:1
אמר ר' אבא בר אבינא מפני מה נסמכה פרשת מרים לפרשת אפר פרה, אלא מלמד שכשם שאפר פרה מכפר, כך מיתת צדיקים מכפרת, אמר ר' [יודן] מפני מה נסמכה מיתת אהרן לשיבור הלוחות, מלמד שקשה לפני הקב"ה מיתת צדיקים כשיבור הלוחות. אמר ר' חייא בר אבא באחד בניסן מתו בניו של אהרן, למה מזכיר מיתתן ביום הכפורים, (א"ל) [אלא] ללמד כשם שיום הכפורים מכפר כך מיתת צדיקים מכפרת, ומנין שיום הכפורים מכפר, שנאמר כי ביום הזה יכפר עליכם לטהר אתכם (ויקרא טז ל), ומנין שמיתת צדיקים מכפרת, שנאמר ויקברו את עצמות שאול וגו' ויעתר אלהים לארץ אחרי כן (ש"ב כא יד).