Rashi, in his commentary to Bereishis 19:1 tells us:
שני TWO — One to destroy Sodom, the other to rescue Lot — it was he who had come to heal Abraham — whilst the third, who had come to make the announcement to Sarah, had departed as soon as he had carried out his mission (Midrash Tanchuma, Vayera 8).
Aish has a really nice explanation in which exactly your question is asked. It offers the following solution, based on the Rashi mentioned above.
Why did three angels come to Abraham, but only two go to Lot?
The answer is that since Michael's sole mission was to tell Sarah she would become pregnant, he had no business in Sodom. Therefore, upon leaving Abraham's tent he went back to his post at God's Holy Throne. But Gabriel, who was left with his task of destroying Sodom, and Raphael, who was commanded to save Lot, had not yet finished their tasks, and continued to Sodom. (Rashi - Genesis 19:1 and 9:16)
So, each angel has a task. Each situation needs a certain approach. If a certain approach is not suitable for that situation, the angel will not accompany the other angels.
Edit: and all of this can be applied to the teaching of the Maharal in his Gur Aryeh, which @RabbiKaii brought down below. Thanks RabbiKaii!