The Lord tells us that he will look upon only one kind of man, and that is the man who humbles himself and in a wounded spirit still reveres the word of God (cp. Isaiah 62:2). Why would God look to this man? I think it is because there is reason to believe that this is how God is. He is revealed as God who suffers with us, as we see in John 3:16 and in the life of Jesus himself (cp. John 1:18). God gave his word to Abraham that all nations would be blessed in him (i.e. in Abraham; cp. Genesis 18:18). In Genesis 17:16 God promised Abraham that Sarah would have a son although her womb was dead. Once the Lord has given his word, it won’t return to him void, but his word will accomplish all that God intended to do (Isaiah 55:11).
Of course this theology had to be learned. Abram, for example, didn’t understand this when he left Ur in answer to the call of God who appeared to him. What Abraham knew was that God had planned to bless him, and make him a great nation. After years of waiting and disappointment, Abraham and Sarah thought they knew how God intended to carry out his plan. They were wrong to assume God would use Hagar to give Abraham the promised seed, because, as later becomes clear, God blesses marriage to one man and one woman (Matthew 19:3-8). This understanding of God, although probably unknown in Abraham’s day, is behind God’s unwillingness to be bound by man’s indiscretion (cp. Isaiah 55:8-9).
Obviously, Abraham had become very attached to Ishmael (Genesis 17:18; 21:10-11), but Abraham endured the pain of the consequences of his own decision and obeyed God by giving Hagar her freedom and allowing his son to go with his mother (Genesis 21:14). From time to time we must make a decision to carry out what we intended in our effort to honor God or cast it aside in favor of doing what God intended for us from the beginning. It may be difficult to cast off years, perhaps decades of labor, as worthless effort as far as serving God is concerned (cp. Philippians 3:8), but when there is no plan-B, we simply have no other place to go but with the Lord (cp. John 6:66-69), confident that God is able to cause all things to work together for our good (Romans 8:28; cp. Genesis 21:12-13).
In Genesis 21:22-34 we are given an account of Abraham’s covenant with Abimelech, but we must not consider it something that takes place immediately after Hagar is sent away. This covenant may have transpired sometime in the middle of Genesis 21:1-20. Beersheba was named as a result of Abraham’s covenant with Abimelech (Genesis 21:31), but Hagar wandered in the wilderness of Beersheba (cp. Genesis 21:14). If the wilderness wasn’t given this name before she left, how could it be said she wandered through Beersheba?
Another thing we need to keep in mind, as far as Abraham and Abimelech are concerned, is that in the beginning Abimelech had no regard for Abraham (Genesis 20:2). The fact that we see him come to Abraham to parley, thus treating him as an equal, shows that something has changed. What changed? Well, according to Abraham, there was no fear of God in the land where Abimelech ruled when the two first met (Genesis 20:11). That seems to have changed after a few years (Genesis 21:22-23), and by the time of Genesis 21 Abimelech wants Abraham to make a covenant of peace with him, because, evidently, Abimelech fears Abraham’s God. Nevertheless, we have to ask: if God could destroy Abimelech, as we are told in Genesis 20, why would Abimelech believe Abraham would want to make peace with him? After all, Abraham seems to be holding all the trump cards with this powerful God working with him. It is easy to presume logically that, if Abraham wished to do so, he could have destroyed Abimelech, because God was on Abraham’s side (cp. Genesis 14 where God was with Abraham when he made war with the powerful eastern cities of Mesopotamia for Lot’s sake).
We also must not believe that Abimelech was truthful in every respect when he came to Abraham. For example, he did not treat Abraham very well in the beginning when he came and took Sarah away from Abraham (Genesis 20:2; cp. 21:23). Furthermore, we should not believe that Abimelech didn’t know about his servants violent behavior toward Abraham’s servants as that pertained to a well dispute (cp. Genesis 21:25-26). Rather, we could take from this that Abimelech saw in Abraham’s peaceful response toward a violent event evidence that peace between them might be a possibility rather than pursuing the uncertain course of war.
As for Abraham, we see that he recognized he was a pilgrim in a strange land, not having the rights of citizenship, so he didn’t presume any. Rather than pursuing a violent course, which may, in truth, have been a trap to lure Abraham into a position whereby Abimelech might have destroyed him as an adversary, Abraham threw his cares upon the Lord’s promise that God would make him a great nation. By this time, Abraham was able to see that his marriage to Hagar was not a wise choice. God had Isaac in mind all the while, not Ishmael. Therefore, Abraham didn’t need to respond to violence by taking measures into his own hands once more. God will do what he wants to do without Abraham helping the cause.
Abraham’s treaty with Abimelech also reveals his own wisdom in dealing with matters of worldly concern. Abraham knew that Abimelech was not his friend, but he also knew Abimelech wanted to secure a peace treaty with Abraham rather than pursue the uncertain course of warfare. Therefore, Abraham added an addendum to Abimelech’s proposal. Abimelech would have provided the animals for sacrifice between which both he and Abraham would have walked to ratify the treaty between them (cp. Genesis 15:8-11, 17). Abraham, however, offered ewe lambs to Abimelech as a gift. What Abraham did was, in effect, tell Abimelech: “I know you wish to share in my good fortune (cp. Genesis 12:3), but in order for you to participate in this, you need to recognize my right to water.” It would be useless for Abraham to make peace with someone who didn’t recognize his right to live in the land.
Having made the treaty with Abimelech, Abraham made public the acknowledgment of his faith in God by planting a tamarisk tree in Beersheba and worshiped the Everlasting God, or the God of the ages—the unchanging nature of God from age to age. In other words, no matter what choices man might make, God is above it all. Hagar doesn’t matter and couldn’t help fulfill God’s promise to Abraham, and Abimelech doesn’t matter and cannot prevent God from keeping his promise to Abraham. God is and remains God no matter what occurs!
 Abraham was not bound by law to allow Ishmael to leave with his mother. Hagar was a slave. She was given her freedom, and the law which Abraham’s culture submitted to or recognized was that any newborn of a slave, while that one remained a slave in his or her master’s household would be the property of the slave owner and not the slave who bore the child (cp. Exodus 21:2-4).