We see this almost from the get-go. When Avimelech realizes that the woman he has taken is another man's wife, he speaks to God and says (Genesis 20:4)
ד וַאֲבִימֶלֶךְ, לֹא קָרַב אֵלֶיהָ; וַיֹּאמַר--אֲדֹנָי, הֲגוֹי גַּם-צַדִּיק תַּהֲרֹג. | 4 Now Abimelech had not come near her; and he said: 'LORD, wilt Thou slay even a righteous nation? |
There is a very strong echo here to an earlier scene with Abraham. Specifically, it is the scene in which Abraham pleads for Sodom and Gomorrah (Chapter 18).
The cry that Abraham espouses- "Shall not the Judge of all the earth do justly?" is echoed by Avimelech. "I didn't know," Avimelech claims. "I acted in the innocence of my heart and with clean hands. I ought to be judged fairly!"
(A point of interest is that God agrees that he acted in the innocence of his heart but not with clean hands. That part is omitted from the answering verse.
Why isn't Abimelech considered to have acted with clean hands?
Rashi comments to this and explains that while it is true Abimelech originally took Sarah innocently, not having known she was another man's wife, it is only Godly intervention that prevents him from consorting with her. As becomes clear later in the chapter, Abimelech and all of his court are stricken with some kind of ailment that stops up women's wombs and renders them infertile (Genesis 20:18).)
Here is the important part. Once Abimelech recognizes that God has brought this plague upon him, he does the right thing and relinquishes Sarah. But not without a parting shot- note the following odd phrase:
וּלְשָׂרָ֣ה אָמַ֗ר הִנֵּ֨ה נָתַ֜תִּי אֶ֤לֶף כֶּ֙סֶף֙ לְאָחִ֔יךְ הִנֵּ֤ה הוּא־לָךְ֙ כְּס֣וּת עֵינַ֔יִם לְכֹ֖ל אֲשֶׁ֣ר אִתָּ֑ךְ וְאֵ֥ת כֹּ֖ל וְנֹכָֽחַת׃
And to Sarah he said, “I herewith give your brother a thousand pieces of silver; this will serve you as a covering of the eyes before all who are with you, and you are cleared before everyone.”
There are several different interpretations as to what Avimelech means when he talks about giving Sarah money "as a covering of the eyes" before all who are with you. However, some commentators interpret that Abraham and Sarah blinded Abimelech and kept him from seeing clearly by pretending to be sister and brother. Therefore, an angry Avimelech curses Sarah (see the Torah Temimah) and eventually the curse comes true.כסות עינים. א"ר יצחק, לעולם אל תהא ברכת הדיוט קלה בעיניך, שהרי אבימלך קלל את שרה ונתקיים בזרעה, שנאמר הנה הוא לך כסות עינים, אמר לה, הואל וכסית ממני שהוא אישך וגרמת לי הצער הזה, יהי רצון שיהיו לך בני כסויי עינים, ונתקיים בזרעה, שנאמר ביצחק (פ' תולדות) ותכהין עיניו מראות י.
(ב"ק צ"ג א')
There is another scene just prior in which blindness was referenced. This is the famous scene where the angels come to Sodom and Gomorah and the members of the city want Lot to give them over to be sodomized. Lot tries to argue with the mob and offers them his virgin daughters in lieu of his guests but the people of Sodom press him and say they will do worse to him. They attempt to break down the door.
Then the angels cause blindness to fall upon every single one of them (which, if we are paralleling our two scenes, would be the equivalent to Avimelech and his entire court being unable to bear children).
This is the moment at which the people of Sodom can choose to see the hand of God at work or choose to refuse it. They can decide to give up on their desire to sodomize the men, recognizing that God (or more precisely, His angels) have forbidden them to do it. This is what Abimelech does in our scene- recognizing that something mysterious and miraculous is in play, he speaks to God, speaks to Abraham, makes reparations to Sarah and relinquishes her.
But this is NOT what the people of Sodom do. They are stubborn and they will refuse to recognize God's intervention- quite literally if it kills them.
יא וְאֶת-הָאֲנָשִׁים אֲשֶׁר-פֶּתַח הַבַּיִת, הִכּוּ בַּסַּנְוֵרִים, מִקָּטֹן, וְעַד-גָּדוֹל; וַיִּלְאוּ, לִמְצֹא הַפָּתַח. | 11 And they smote the men that were at the door of the house with blindness, both small and great; so that they wearied themselves to find the door. |
Those three words ought to shock you. When these people are blinded, a completely supernatural event, their reaction is NOT, like Abimelech, to give up on the pursuit. They do not make reparations, pay Lot, pay the guests they have tried to seize (exactly as Abimelech took Sarah)- no, they simply keep on grasping for the door and they only give up when they have literally become so weary that they have to.
It is only AFTER this event that the angels turn to Lot and say
We learn that this was actually a test.
Abimelech passed the test but the men of Sodom failed.
Here's the test, in short: Someone who is not quite who you think they are (an angel disguised as a man, a wife who appears merely to be someone's sister) appears in your place of residence. You either take them or try to take them. You are stricken by a mysterious plague (literal blindness or a plague caused by the fact that you were blind to the truth of the situation). Do you recognize God's hand in these events and immediately attempt to make reparations? Or do you deny God's role completely?
If you're Abimelech, you recognize God. Thus, you pass the test. You demonstrate there is at least some fear of God in your land.
If you're the Sodomites, you refuse to recognize God. You fail the test. You and your city are totally destroyed.
Here's why it matters- because Abraham bears witness to it. He sees a situation in which God does allow someone who did wrong but who later made reparations to be saved. Indeed, he is the agent that helps it to happen because he prays on Avimelech's behalf (Genesis 20:17).
Where else do we see someone praying on a monarch's behalf?
It happens with Moses.
Look at Exodus 9:27-30.
Notice the echoes going on in this scene. Pharaoh admits that he and his people are wicked while God is righteous and just. It seems like he is going to behave as Abimelech does and finally relinquish the people once and for all (just as Abimelech relinquishes Sarah). But Moses chides him, saying that while he will pray for him he knows that they do not truly fear God. Pharaoh and his countrymen are more similar to the people of Sodom, who will weary themselves trying to keep what they want, than Abimelech, who was willing to give it up eventually.
So what is going on in this perek? This perek is a meditation on God's justice. We learn something about how His justice works. God does not assume that everyone knows and plays by His rules from the beginning. He does, however, insist that once He brings punishment upon them (whether blindness or a plague that causes infertility) they then acknowledge His presence and relinquish what is not theirs (whether it is the men who are really angels, or the sister who is really a wife, or the slaves who are really God's chosen.) If they are willing to do this, He is merciful - as Abraham himself and we as the readers witness in this chapter. If they are unwilling...God has already shown what will happen in His destruction of Sodom.