Right after it says that the malachim left Avraham's home to go to Sdom, Hashem says, "Erdah na v'er'eh...," (18:21) let me go down and see what's going on in Sdom and judge whether they really deserve to be punished.
Shouldn't Hashem have judged Sdom *before* the malachim started off there? After all, the malachim's mission was to destroy Sdom and save Lot. If Hashem hadn't made up his mind yet, what were the malachim going for?
The Shem m'Shmiel explains that sending the malachim was part of Hashem's process of judging Sdom. Experiencing something holy should cause a person to reflect and improve. Hashem sent the malachim to Sdom as a test to see what would happen. If Sdom would remain status quo, with no change and no reaction, that would prove that there was nothing left that could be saved. If they reacted positively, then there was still a chance they could be spared.
Look at Lot's behavior in contrast to that of Sdom. Lot ran away from Avraham to the spiritually worst place in the world, Sdom, because it was beautiful land that had plentiful pasture. Lot did not seem like the type individual who would stick his neck out for Torah and mitzvos. Yet we see in our parsha that Lot does a turnaround and does hachnasas orchim even at great risk to his life. What happened? The answer is that the visit of the malachim awakened something inside him that had long been dormant. When exposed to the great of the malachim, Lot could not help but return to the good practices that he had learned once upon a time from Avraham. The experience showed that there indeed was goodness still inside him, and therefore, he was saved.
The people of Sdom encountered those same malachim but failed to react. For Lot, it was a turning point back to mitzvos.