"But God came to Abimelech in a dream by night, and said to him, 'Indeed you are a dead man because of the woman whom you have taken, for she is a man's wife.' But Abimelech had not come near her; and he said, 'Lord, will You slay a righteous nation also? Did he not say to me, "She is my sister"? And she, even she herself said, "He is my brother." In the integrity of my heart and innocence of my hands I have done this.' And God said to him in a dream, 'Yes, I know that you did this in the integrity of your heart. For I also withheld you from sinning against Me; therefore I did not let you touch her. Now therefore, restore the man's wife; for he is a prophet, and he will pray for you and you shall live. But if you do not restore her, know that you shall surely die, you and all who are yours'" (Gen. 20:3-7).
This section fascinates me. We have God communicating with a king via a dream, and Abimelech is able to dialogue with God and knows that this is not some dream of fancy or fiction! God reveals the truth about Sarah and tells the king that he is a dead man for what he has done (i.e., taken her with the intent to be sexually intimate with her). Abimelech rightly pleads ignorance and for mercy. He was only going by what both Abraham and Sarah had told him; he believed Sarah was unmarried and available. God Himself affirms that He prevented Abimelech from unknowingly committing adultery with Sarah. This is intriguing to me, and it makes me wonder how this was done. It would seem likely that God kept Abimelech busy with other things (via circumstances) or sick and this rendered him unable to make sexual advances toward Sarah up to that point. God Almighty, who rules in the kingdoms of men (cf. Dan. 4:17), is very involved in our world and our circumstances--even today. Much of His present-day activity is unknown to us specifically, of course, but that doesn't make it any less real. God did not want Abimelech to die for his ignorance so He explains what must be done. The text will show the king to be very reasonable. He is wise to desire to do what is right more than he desires Sarah.
"So Abimelech rose early in the morning, called all his servants, and told all these things in their hearing; and the men were very much afraid. And Abimelech called Abraham and said to him, 'What have you done to us? How have I offended you, that you have brought on me and on my kingdom a great sin? You have done deeds to me that ought not to be done.' Then Abimelech said to Abraham, 'What did you have in view, that you have done this thing?' And Abraham said, 'Because I thought, surely the fear of God is not in this place; and they will kill me on account of my wife. But indeed she is truly my sister. She is the daughter of my father, but not the daughter of my mother; and she became my wife. And it came to pass when God caused me to wander from my father's house, that I said to her, "This is your kindness that you should do for me: in every place wherever we go, say of me, 'He is my brother'"'" (Gen. 20:8-13).
Abimelech did not delay to take care of this very serious situation. Early in the morning he informed all of his men of the truth about Abraham and Sarah. He rightly rebukes Abraham for his deception. It was a deed "that ought not to be done." Abraham replies with a lame excuse and then explains that Sarah really is his sister--or half-sister at least. Then he reveals that this deception has been his practice everywhere they went! Such cannot be justified, though I suppose it is understandable. Men often lie to attempt to protect themselves when they are afraid.
The chapter concludes with Abimelech giving Abraham many gifts as well as returning Sarah to him. Clearly Abraham was wrong about the "fear of God" not being in Gerar! Abimelech is now clearly vindicated before all. "So Abraham prayed to God; and God healed Abimelech, his wife, and his female servants. Then they bore children; for the LORD had closed up all the wombs of the house of Abimelech because of Sarah, Abraham's wife" (Gen. 20:17,18). It is of interest to me why God reacted so strongly against Abimelech's ignorant intent to make Sarah his own. The text doesn't explain but surely it has to do with the promises God had made to Abraham. Abimelech would not be allowed to interfere with their fulfillment--even if he only interfered out of ignorance! The will of God will be fulfilled--no matter what!