The Midrash of "Gather"
And the children of Israel, even the whole congregation, came into the wilderness of Zin in the first month; and the people abode in Kadesh; and Miriam died there, and was buried there (Numbers 20:1). This is what scripture says: A time to keep silence and a time to speak (Ecclesiastes 3:7).
This narrator jumps from the second day of Nisan in the second year of the exodus from Egypt to the first of Nisan in the fortieth year. For just prior to this passage we find written the laws of the red heifer, which was burned on the second of the month, and on the first the Tabernacle was erected. [ . . . ]
And why is the death of Miriam juxtaposed to the laws of the red heifer? To teach that just as the red heifer purifies the impure, similarly the performance of righteous deeds offers merit to the one who performs it. And this is why we find written: Whatever that unclean person touches shall be unclean; and the soul who touches him shall be unclean until evening (Numbers 19:22).
Another explanation: And the children of Israel, even the whole congregation, came. This is the meaning of what is said: But He raised up their children in their stead (Joshua 5:7); that is why it said that the whole congregation arrived, for the decree that those who left Egypt would be destroyed applied to those over the age of twenty. Had those [over twenty] all died at once and had the survivors entered the land immediately, they would have come as a contemptible people, without elders or warriors, the oldest just nineteen years old. Forty years [in the desert] was decreed for them—each year corresponding to a day—so that as these would die, others would stand up to replace them. Thus, [at the end,] the oldest of them would be sixty years old. This is what He did to them so that they would enter the land in glory. An entire congregation passed away, chiefs of thousands, the first ones, who left Egypt, and they were replaced by their children’s children. And the children of Israel, even the whole congregation, came.
Another explanation: And the children of Israel, even the whole congregation, came. This is the meaning of what is said: That because of evil the righteous was taken away (Isaiah 57:1). One should not think only evildoers feel the calamity of the passing of the righteous; rather, the righteous feel the passing of the righteous as well. For the decree against Moses and Aaron was not put into effect until after Miriam’s passing. This is why it says: Miriam died there and was buried there; they felt the loss of her passing.
Another explanation: Miriam died there and was buried there. This teaches that the Omnipresent judges individuals individually and groups by group, as it says: Joseph died, and all his brothers, by themselves, and all that generation, by themselves [see Exodus 1:6]. For these three righteous individuals [Moses, Aaron, and Miriam] were not condemned to die. Similarly, in this case a decree was meted out against the entire generation: Not one of these men, this evil generation, shall see the good land (Deuteronomy 1:35), and the entire generation died because of that edict. But these three righteous individuals did not die with them because of that decree, which is why it says: Do not sweep me away with sinners (Psalms 26:9). Once that entire generation had died, only then was the decree carried out against those three, based on their own merits. Miriam died there and was buried.
Another explanation: Miriam died there. She was the only one of all the women who left Egypt to die, for none of the other women died in the desert, as it says: All the people that came forth out of Egypt, that were males, even all the men of war, died in the wilderness by the way, after they came forth out of Egypt (Joshua 5:4), but the women did not die. And why did she die? Because of the wellspring that was given in her merit, for after the wellspring was withdrawn, she could not continue to live.
Another explanation. For she was equivalent to Moses and Aaron in her greatness. The three of them all sustained the Israelites [equally], so it would have been inappropriate for them to die while Miriam remained. For this reason, she died before them.
Published in: The Posen Library of Jewish Culture and Civilization, vol. 3: Encountering Christianity and Islam.