In the last section, God provided reassurance of His promises to Abraham (and some gentle but firm correction). Now His visit is coming to an end. But, before He goes, He mentions the purpose of His next order of business. He intends, from verses 20-21, to investigate the evil of Sodom and Gomorrah. If you're like me, you're asking questions like:
Why does an omniscient God need to investigate anything?
Why bother telling Abraham about it?
Why did God wait for the evil of Sodom and Gomorrah to get so bad?
Before we answer these questions, let's first lay out the exchange between Abraham and God. God initiates the conversation by telling Abraham His plans. He waits and gives Abraham a chance to respond (this is implied in v. 22 when the two men leave and God remains), and He is the one who ends the conversation (verse 33 says, "when the LORD had finished speaking with Abraham," not the other way around). Now let's consider those first two questions.
It's obvious that an omniscient God doesn't need to investigate like we do. But this section is less about a declaration of what God intends and is more of a dialog He is opening with Abraham. When He waits for Abraham to respond, I have the impression He is asking, "What will I find when I investigate the cities of Sodom and Gomorrah?"
Abraham's response gives us a clue to the third question. He jumps straight to language that indicates destruction when he says, "Will you sweep away the righteous with the wicked". When I read this, I was a little distracted by a statement that seemed disconnected. My mind said, "wait, what? When did the conversation change? We were considering investigative tourism and now this? Have I missed something?"
The answer was yes, I had missed something. Abraham was familiar with the character of God. And, he had a very good example of how God dealt with wickedness from the story of Noah's flood. When I wrote about the flood, I mentioned how God waited patiently for repentance but He acted firmly and dramatically to destroy the wicked. It seems Abraham saw the cities of Sodom and Gomorrah following a path similar to the wicked of Noah's day and, given what he knew from that story, he made an intuitive leap in the conversation. God's waiting posture asked the question of "what will I find" but Abraham doesn't waste time (they both already know what God will find there) and essentially asks, "how will you respond to the wickedness you find?" (v23-25)
The remainder of the chapter seems to be an interesting lesson in bartering where Abraham asks God to withhold destruction if some number of righteous people can be found in Sodom and Gomorrah. God finally ends their conversation after he agrees to spare the cities if 10 righteous people can be found there. I find myself wondering why Abraham didn't push things further but I suspect there is some nuance of bartering in the Ancient Middle East that I don't fully understand. Even so, it is clear that God was more than gracious given how He regards Abraham (v.17-19) and His willingness to include him and engage with him in a way he could understand.