Rashi (Rabbi Shlomo Itzhaki, 1040-1105) was a medieval French rabbi who wrote a comprehensive commentary on the Tanakh. Rashi's great because he presents the basic meaning of the text in a clear and concise fashion. His comments usually try to answer a burning question that an ordinary reader might have.
But, Rashi only wrote down his answers - NOT the questions! So the first thing to do is always to ask: "What's bothering Rashi?" Once you understand the question Rashi's responding to, his answer will make a lot more sense.
In this packet I've given you first the relevant Torah texts, then Rashi's comment on Genesis 18:2, then two Midrashim that Rashi brings in to help answer the question.
(24) Abraham was ninety-nine years old when he circumcised the flesh of his foreskin,
Abraham just "cut" his covenant with God at the tail end of the previous chapter, so he must have still been recovering when the men/angels show up.
(1) The LORD appeared to him by the terebinths of Mamre; he was sitting at the entrance of the tent as the day grew hot. (2) Looking up, he saw three men standing near him. As soon as he saw them, he ran from the entrance of the tent to greet them...
(7) Then Abraham ran to the herd, took a calf, tender and choice, and gave it to a servant-boy, who hurried to prepare it. (8) He took curds and milk and the calf that had been prepared and set these before them; and he waited on them under the tree as they ate. (9) They said to him, “Where is your wife Sarah?” And he replied, “There, in the tent.” (10) Then one said, “I will return to you next year, and your wife Sarah shall have a son!” Sarah was listening at the entrance of the tent, which was behind him.
(15) As dawn broke, the angels urged Lot on, saying, “Up, take your wife and your two remaining daughters, lest you be swept away because of the sins of the city.” (16) Still he delayed. So the men seized his hand, and the hands of his wife and his two daughters—in the LORD’s mercy on him—and brought him out and left him outside the city. (17) When they had brought them outside, one said, “Flee for your life! Do not look behind you, nor stop anywhere in the Plain; flee to the hills, lest you be swept away.” (18) But Lot said to them, “Oh no, my lord! (19) You have been so gracious to your servant, and have already shown me so much kindness in order to save my life; but I cannot flee to the hills, lest the disaster overtake me and I die. (20) Look, that town there is near enough to flee to; it is such a little place! Let me flee there—it is such a little place—and let my life be saved.” (21) He replied, “Very well, I will grant you this favor too, and I will not annihilate the town of which you have spoken. (22) Hurry, flee there, for I cannot do anything until you arrive there.”
Rashi comments always begin with the words from the verse he's going to give an explanation of in bold. In order to explain how a passage makes sense, Rashi often has to refer to other verses in Tanakh. He was in an incredible scholar who knew the whole Tanakh by heart, so he didn't bother to cite any of his sources. Modern editions include verse citations in parentheses. Rashi also reads the Tanakh in light of the Midrash, trying to make everything harmonize. When he refers to a collection of Midrash (like Genesis Rabbah, as you'll see below) those references are in parentheses too.
(ב) והנה שלשה אנשים אֶחָד לְבַשֵׂר אֶת שָׂרָה וְאֶחָד לַהֲפֹךְ אֶת סְדוֹם וְאֶחָד לְרַפְּאוֹת אֶת אַבְרָהָם, שֶׁאֵין מַלְאָךְ אֶחָד עוֹשֶׂה שְׁתֵּי שְׁלִיחֻיּוֹת (בראשית רבה) תֵּדַע לָךְ, שֶׁכֵּן כָּל הַפָּרָשָׁה הוּא מַזְכִּירָן בִּלְשׁוֹן רַבִּים וַיֹּאכֵלוּ, וַיֹּאמְרוּ אֵלָיו, וּבַבְּשׂוֹרָה נֶאֱמַר וַיֹּאמֶר שׁוֹב אָשׁוּב אֵלֶיךָ, וּבַהֲפִיכַת סְדוֹם הוּא אוֹמֵר כִּי לֹא אוּכַל לַעֲשׂוֹת דָבָר לְבִלְתִּי הָפְכִּי וּרְפָאֵל שֶׁרִפָּא אֶת אַבְרָהָם הָלַךְ מִשָּׁם לְהַצִּיל אֶת לוֹט; הוּא שֶׁנֶאֱמַר וַיְהִי כְהוֹצִיאָם אוֹתָם הַחוּצָה וַיֹּאמָר הִמָּלֵט עַל נַפְשֶׁךָ, לָמַדְתָּ שֶׁהָאֶחָד הָיָה מַצִּיל (בראשית רבה):
(2) והנה שלשה אנשים THREE MEN — one to announce to Sarah the birth of a son, one to overthrow Sodom, and one to cure Abraham, for one angel does not carry out two commissions. (Genesis Rabbah 50:2) You may know that this is so because throughout this section it mentions them in the plural — “as they ate” (Genesis 18:8), “they said to him” (Genesis 18:9) — while in the case of the announcement it states, (Genesis 18:10) “Then one said, I will return to you”, and with regard to the overthrow of Sodom it says (Genesis 19:22) “For I cannot do anything” and (Genesis 19:21) “I will not annihilate the town”. Raphael, who healed Abraham, went there to rescue Lot; that explains what is stated (Genesis 19:17) “When they had brought them outside, one said, 'Flee for your life!'” You learn from this that only one of these acted as rescuer. (Genesis Rabbah 50:2)
Genesis Rabbah is a collection of rabbinic midrash on the book of Genesis from around 300-500 CE.
(ב) תנא, אין מלאך אחד עושה שתי שליחות, ולא שני מלאכים עושים שליחות אחת, ואת אמרת שני?! אלא, מיכאל אמר בשורתו ונסתלק, גבריאל נשתלח להפוך את סדום, ורפאל להציל את לוט.
(2) It was taught: One angel does not carry out two commissions, and two angels do not carry out one commission. And you say "two"!? (Genesis 19:1) Rather, Michael said his tidings and departed, Gabriel was sent to overthrow Sodom, and Raphael to rescue Lot.
Bava Metzia is a tractate (like a volume of an encyclopedia) of the Talmud. Rashi doesn't cite this Midrash specifically, but it seems like he's got it in the back of his mind as well.