In Parshas Chukas we are told that following Miriam's death, the be'er, the water source for the Bnei Yisroel, dried up.
It writes in 20:1-2:
וַיָּבֹ֣אוּ בְנֵֽי־יִ֠שְׂרָאֵ֠ל כׇּל־הָ֨עֵדָ֤ה מִדְבַּר־צִן֙ בַּחֹ֣דֶשׁ הָֽרִאשׁ֔וֹן וַיֵּ֥שֶׁב הָעָ֖ם בְּקָדֵ֑שׁ וַתָּ֤מׇת שָׁם֙ מִרְיָ֔ם וַתִּקָּבֵ֖ר שָֽׁם׃ וְלֹא־הָ֥יָה מַ֖יִם לָעֵדָ֑ה וַיִּקָּ֣הֲל֔וּ עַל־מֹשֶׁ֖ה וְעַֽל־אַהֲרֹֽן
The Children of Israel, all the congregation came to the wilderness of Zin on the first month, and the people stayed at Kadesh. Miriam died there and was buried there. The congregation was without water, and they joined against Moses and Aaron.
This reminded me of the Gemara in Taanis 9a which famously relates:
מֵיתִיבִי, רַבִּי יוֹסֵי בְּרַבִּי יְהוּדָה אוֹמֵר: שְׁלֹשָׁה פַּרְנָסִים טוֹבִים עָמְדוּ לְיִשְׂרָאֵל, אֵלּוּ הֵן: מֹשֶׁה וְאַהֲרֹן וּמִרְיָם. וְשָׁלֹשׁ מַתָּנוֹת טוֹבוֹת נִיתְּנוּ עַל יָדָם, וְאֵלּוּ הֵן: בְּאֵר, וְעָנָן, וּמָן. בְּאֵר — בִּזְכוּת מִרְיָם, עַמּוּד עָנָן — בִּזְכוּת אַהֲרֹן, מָן — בִּזְכוּת מֹשֶׁה. מֵתָה מִרְיָם — נִסְתַּלֵּק הַבְּאֵר, שֶׁנֶּאֱמַר: ״וַתָּמׇת שָׁם מִרְיָם״, וּכְתִיב בָּתְרֵיהּ: ״וְלֹא הָיָה מַיִם לָעֵדָה״, וְחָזְרָה בִּזְכוּת שְׁנֵיהֶן.
The Gemara raises an objection from a baraisa: Rabbi Yosei, son of Rabbi Yehuda, says: Three good sustainers rose up for the Jewish people during the exodus from Egypt, and they are: Moshe, Aharon and Miriam. And three good gifts were given from Heaven through their agency, and these are they: The well of water, the pillar of cloud, and the manna. He elaborates: The well was given to the Jewish people in the merit of Miriam; the pillar of cloud was in the merit of Aaron; and the manna in the merit of Moses. When Miriam died the well disappeared, as it is stated: “And Miriam died there” (Numbers 20:1), and it says thereafter in the next verse: “And there was no water for the congregation” (Numbers 20:2). But the well returned in the merit of both Moses and Aaron. (Sefaria translation and additional notation)
However, how do we understand the zechus Miriam (or Moshe and Aharon's for that matter), in light of another Gemara in Bava Metzia 86b which notes that since Avraham attended to the needs of the visiting angels, the Bnei Yisroel merited these three things in the desert:
וכן תנא דבי רבי ישמעאל בשכר שלשה זכו לשלשה בשכר חמאה וחלב זכו למן בשכר והוא עומד עליהם זכו לעמוד הענן בשכר יוקח נא מעט מים זכו לבארה של מרים
And likewise the school of Rabbi Yishmael taught: In reward for three (acts of hospitality that Aהraham performed for the angels), his descendants merited three rewards. In reward for providing them with curd and milk, the Jewish people merited the mann; in reward for: “And he stood [omed] by them,” the Jews merited the pillar [amud] of cloud; in reward for Abraham saying: “Let now a little water be fetched,” they merited the well of Miriam.
Do we understand it that Avraham ensured the initial merit, and then Moshe, Aharon and Miriam were the ones whose merit brought it into actuality or is there another mechanism in place?