After Sarah was able to have her own child, and he survived infancy, she began to get angry with Abraham's other son, Ishmael. He would have been a constant reminder of her own sin. God blessed Ishmael, but he was not able to inherit the promises given to Abraham. (See: [[rc://en/tw/dict/bible/kt/sin]], [[rc://en/tw/dict/bible/kt/inherit]] and [[rc://en/tw/dict/bible/kt/promise]] and [[rc://en/tw/dict/bible/kt/bless]])
According to the law at this time, Hagar was able to gain her freedom from slavery by abandoning any claim to receive an inheritance. This is why Hagar would have abandoned her son under the tree. (See: [[rc://en/ta/man/translate/figs-explicit]])
The Gentile king, Abimelech, made a covenant or treaty with Abraham. It is possible that he did this because he recognized the power of Abraham's God, but his exact reasons are unknown. (See: [[rc://en/tw/dict/bible/kt/covenant]])