When their combined flocks grew too large to sustain them on the land, Abraham suggested to Lot that they separate. Abraham said he would go left if Lot chose to go right, or he would go right if Lot chose to go left. Lot had his choice of anywhere to settle. Interestingly, Lot pitched his tent NEAR Sodom. (Genesis 13:12).
We meet Lot again, and this time he is living IN the city. (Genesis 14:12.) No longer a sojourner in a tent, he has a house.
The next time we meet Lot he is serving as magistrate FOR the city. (Genesis 19:1).
What is meant by the term in Genesis 19:1, "he was sitting at the gate" is that Lot was part of its government. Middle Eastern men of that time were not simply whittling as they rocked in leisure at the front gate. This term 'sitting at the gate' means they were the officials of the city, both to greet visitors and determine their business, friend or foe; and also to settle disputes among its citizens.
In 2 Peter 2:7–8 Lot is called righteous. We know that God considered him so because he did not destroy Lot when the angels came to overthrow the cities. When brimstone came down, Lot had already been warned to leave. Lot had (weakly) tried to warn the aroused mob that what they were doing were evil deeds (Genesis 19:7). Perhaps he had tried to be a good leader to his household and a righteous example in the city, because the 2 Peter verse says Lot was vexed by the sin all around him.
Putting aside the 'perhapses', when push came to shove, Lot's testimony had been so tarnished that his family thought he was joking when He spoke of imminent judgment from God. Joking.
And if you do not do well, sin is crouching at the door. Its desire is contrary to you, but you must rule over it. (Genesis 4:6b).
Despite the city's reputation for evil and sin, Lot had chosen to pitch his tents near it. This was a mistake. The Bible warns us to flee from sin, not test it. (1 Corinthians 6:18, Ephesians 4:27)
My own prayer is that I beseech the Lord to aid me in fleeing sin, cutting it off, resisting it. (Genesis 39:12, Matthew 5:30, Hebrews 12:4), so that when I speak of Him, the words are taken seriously. What a crushing blow to love the Lord and to have hated sin, but to have lived so weakly that when speaking of Him, it's a joke to the hearers. Lord, let it not be so. Let my words be honoring to You and let my life exalt you also.