On the pasuk (Bamidbar 20:1) וַיָּבֹ֣אוּ בְנֵֽי־יִ֠שְׂרָאֵל כָּל־הָ֨עֵדָ֤ה מִדְבַּר־צִן֙ בַּחֹ֣דֶשׁ הָֽרִאשׁ֔וֹן וַיֵּ֥שֶׁב הָעָ֖ם בְּקָדֵ֑שׁ וַתָּ֤מָת שָׁם֙ מִרְיָ֔ם וַתִּקָּבֵ֖ר שָֽׁם׃: The Bnei Yisrael, the whole congregation, arrived at the wilderness of Zin in the first month, and the people stayed at Kadesh. And Miriam died there and she was buried there.
Rashi writes:
כל העדה= עֵדָה הַשְּׁלֵמָה, שֶׁכְּבָר מֵתוּ מֵתֵי מִדְבָּר וְאֵלּוּ פֵרְשׁוּ
לַחַיִּים: - כל העדה , the WHOLE congregation — The congregation in
its entirety, for those who were to die in the wilderness in
consequence of their sin had already died, but these had been
expressly mentioned for life.
ותמת שם מרים. לָמָּה נִסְמְכָה פָרָשַׁת מִיתַת מִרְיָם לְפָרָשַׁת פָּרָה
אֲדֻמָּה? לוֹמַר לָךְ, מַה קָּרְבָּנוֹת מְכַפְּרִין, אַף מִיתַת צַדִּיקִים
מְכַפֶּרֶת (מועד קטן כ"ח):
AND MIRIAM DIED THERE — Why is the section narrating the death of
Miriam placed immediately after the section treating of the red cow?
To suggest to you the following comparison: What is the purpose of the
sacrifices? They effect atonement! So, too, does the death of the
righteous effect atonement! (Moed Katan 28a).
The Chasam Sofer explains the connection between these two psukim:
ונ"ל בטעם מיתת מרים לכפר על העדה אחר שכבר מתו מרגלים וכל העדה שלמים
ליכנס לא"י עכ"פ הוצרכו כפרה שיהיו ראויים ליכנס ומתה הצדקת לכפר על עון
העדה, ומעתה אחר מיתת הצדקת הי' כולם מהנאמר ואתם הדבקים חיים כולכם
היום.
It seems to me, that the reason for the passing of Miriam was to bring
attonement on the people, since the [people who were involved in the
sin of the] spies had already died, and the rest of the congregation was
wholesome [and] ready to enter Eretz Yisrael, they nevertheless needed
[extra] attonement in order to be able to enter, and thus, the
tzdekes (righteous woman) Miriam passed away to [completely] attone for the sin of the congregation, and now after the death of the tzadekes, they
were all of those about which the pasuk says וְאַתֶּם הַדְּבֵקִים
בהוי"ה אֱלֹהֵיכֶם חַיִּים כֻּלְּכֶם הַיּוֹם. (Devarim 4:4) [But you who cleave to
the L-rd your G-d are alive, all of you, this day].