when the day was hot (B.M. 86b) The Holy One, blessed be He, took the sun out of its sheath so as not to trouble him with wayfarers, but since He saw that he was troubled that no wayfarers were coming, He brought the angels to him in the likeness of men. — [from Gen. Rabbah 48:9, Exod. Rabbah 25:2]Rashi has to put each of these midrashim as commentary on a specific part of a verse, and indeed, in Rashi's view, this is likely primarily brought just to elucidate that specific phrase. In this case, it is commentary on keChom haYom, and explaining why the day was hot. As I mentioned in the previous post, though, many separate judgments and close readings about several different verses often feature into the entirety of the midrash. That is, we may somehow derive that Hashem took the Sun out of its sheath, but how do we know:
1) that this was done so as not to trouble him with wayfarers
2) that Avraham was troubled that no wayfarers were coming
3) that as a result, He brought angels to him in the likeness of men
Some view midrash as a free for all, either because a) it is absolute truth, so all these details they simply knew via tradition, or b) it is allegorical, with the verse as pretext rather than source/prooftext, and so whatever fits the point trying to be made is fine, or c) midrash in general are just a creative outlet, so anything they want to say they feel free to say it.
As I have presented time and again on parshablog, a strong argument can be made that midrah is not a free-for-all, and any detail in a midrash must find at least a foothold in the text. The parsha begins:
a previous post, keChom haYom is taken to refer to the most painful, extreme day of milah, which the text just says he underwent -- the third day, as we see from the incident with Dinah.
We see Hashem appear to him -- וַיֵּרָא אֵלָיו ה, בְּאֵלֹנֵי מַמְרֵא -- and we see that he is sitting by the entrance to the tent, rather than dealing with guests -- וְהוּא יֹשֵׁב פֶּתַח-הָאֹהֶל -- because of the heat of the day -- כְּחֹם הַיּוֹם.
How do we know that Avraham was troubled with not having guests? He was sitting at the opening of the tent, as a type of lookout -- וְהוּא יֹשֵׁב פֶּתַח-הָאֹהֶל. And it is not the case that he just happened to see three men approach. He was looking for them -- וַיִּשָּׂא עֵינָיו וַיַּרְא. Midrashically, we may understand this as him actively lifting up his eyes looking for guests, scanning the horizon. Thus, we know Avraham was troubled, and unhappy with this situation.
How do we know that as a result of this Hashem brought angels in the guise of men? Because the pasuk states וַיִּשָּׂא עֵינָיו, וַיַּרְא, וְהִנֵּה שְׁלֹשָׁה אֲנָשִׁים, נִצָּבִים עָלָיו. Behold, all of a sudden, because of the active lifting of his eyes and scanning the horizon for guests, there were now guests available.
Throughout, it is a reading of the pesukim in which there is not just one event following the other, but rather one causing the other.