When Avraham begs G-d to save the city of Sdom and the vicinity if forty or even thirty people can be found, G-d responds, “Lo e’eseh” -- I shall do nothing to the city if that many righteous people are found. However, when Avraham begs G-d to save the city if just twenty or ten people can be found, G-d responds, “Lo ashchis” – I shall not destroy the city on their behalf, but the city will still suffer some punishment. With so few righteous people present, the city cannot get off scott-free.
Why then, asks the Meshech Chochma, does G-d respond to Avraham’s plea to save the city for forty-five righteous people by saying, “Lo ashchis”, I shall not destroy the city, implying that the city will still be punished? If for forty or even thirty righteous people G-d would withhold all punishment from the city, then certainly if forty-five righteous people were present no punishment at all should be administered?!
The Mishna In Pirkei Avos tells us that there are two aspects to G-d’s judgment: “din" and "cheshbon”. The Vilna Gaon explains that “din” is judgment and punishment for a wrongful act. “Cheshbon”, calculation, means making an assessment of the lost opportunity to do good that came as a result of sin.
The Meshech Chochma applies this distinction here. Avraham first asked G-d to spare Sdom if fifty righteous people could be found, ten righteous people in each city. When that failed, Avraham asked that the cities be spared if only nine righteous were found in each, forty-five in total. Imagine having nine righteous people in a city -- if only one person would step forward to do good, there would be a full minyan of good people! What a lost opportunity! With only seven or eight righteous people, each individual could say that one more or less good person would make little difference. But once a city has nine, all it takes is one more to make a qualitative difference.
While the “din” of a having forty-five righteous people may warrant less severity than a city of only forty or thirty righteous people, the “cheshbon” of lost opportunity cries out for an even harsher punishment. Therefore, G-d promised only to spare the cities from destruction if forty-five righteous people were present, but not to excuse the cities completely.
With this conceptual background other details of the story of Sdom fit into place as well. It's not by chance that the destruction of Sdom takes place immediatly after their appointment of Lot as judge. By placing a relatively honest person in a position of leadership and still failing to make any change, the cheshbon of lost opportunity sealed the city's fate. And it's no wonder that the Malachim come to the city even before G-d begins deliberating Sdom's fate and hearing Avraham's plea on their behalf (as noted by the Shem m'Shmuel). The Angels were a burst of spiritual energy that entered the city. Had Sdom been receptive to the presence of Angelic visitors, this moment might have been a turning point for good. The squandering away of this precious last opportunity for change was yet another factor in sealing Sdom's fate.