The entire Hagar story, with Sarah giving Hagar her maidservant to Avrasham to bear children, then complaining because Hagar considers herself >= Sarah, and demanding that Hagar be demoted back to maidservant, and eventually driven out, is very hard to understand.
We start in Lech Lecha, In Bereishit 16:1-3:
וְשָׂרַי אֵשֶׁת אַבְרָם, לֹא יָלְדָה לוֹ; וְלָהּ שִׁפְחָה מִצְרִית, וּשְׁמָהּ הָגָר.
וַתֹּאמֶר שָׂרַי אֶל-אַבְרָם, הִנֵּה-נָא עֲצָרַנִי יְהוָה מִלֶּדֶת--בֹּא-נָא אֶל-שִׁפְחָתִי, אוּלַי אִבָּנֶה מִמֶּנָּה; וַיִּשְׁמַע אַבְרָם, לְקוֹל שָׂרָי.
וַתִּקַּח שָׂרַי אֵשֶׁת-אַבְרָם, אֶת-הָגָר הַמִּצְרִית שִׁפְחָתָהּ, מִקֵּץ עֶשֶׂר שָׁנִים, לְשֶׁבֶת אַבְרָם בְּאֶרֶץ כְּנָעַן; וַתִּתֵּן אֹתָהּ לְאַבְרָם אִישָׁהּ, לוֹ לְאִשָּׁה.
"Now Sarai Abram's wife bore him no children; and she had a handmaid, an Egyptian, whose name was Hagar."
"And Sarai said unto Abram: 'Behold now, the LORD hath restrained me from bearing; go in, I pray thee, unto my handmaid; it may be that I shall be builded up through her.' And Abram hearkened to the voice of Sarai."
"And Sarai Abram's wife took Hagar the Egyptian, her handmaid, after Abram had dwelt ten years in the land of Canaan, and gave her to Abram her husband to be his wife."
One nitpick is that the translation of אִבָּנֶה as "I shall be builded up" in the second pasuk hides the possibility it means "I will have children,"
At any rate, is is strange that after 10 years of not having children, Sarah would offer her maidservant to Avraham to bear children.
However, if we look at the code of Hammurabi, we will see that this is actually typical of the time, and there were laws to that effect:
Code of Hammurabi 144-145:
144. If a man take a wife and this woman give her husband a maid-servant, and she bear him children, but this man wishes to take another wife, this shall not be permitted to him; he shall not take a second wife.
145. If a man take a wife, and she bear him no children, and he intend to take another wife: if he take this second wife, and bring her into the house, this second wife shall not be allowed equality with his wife.
Thus it seems that when a first wife did not bear children, there were two options. The man could take another woman as a wife, or could be given a maidservant, in which case he cannot take a second wife. Even if he does take a second wife, she is not of equal status to the first wife. It also seems that a second wife can only be taken if there is a lack of children from the first, and this would be either if the first wife bore children or her maidservant did.
Sarah, besides wanting a child, prevented Avraham from taking a second wife by giving her maidservant Hagar to Avraham. Further, it seems from the psukim that the maidservant's children are reckoned to be the mistress's (Sarah's), something we see later for certain with Bilhah and Zilpah. This corresponds with the rule that if the maidservant bears him children, he cannot take a second wife - for it is as if the first wife bore him children. This would be the explanation of אוּלַי אִבָּנֶה מִמֶּנָּה.
Lech Lecha continues, with Bereishit 16:4-6
וַיָּבֹא אֶל-הָגָר, וַתַּהַר; וַתֵּרֶא כִּי הָרָתָה, וַתֵּקַל גְּבִרְתָּהּ בְּעֵינֶיהָ.
וַתֹּאמֶר שָׂרַי אֶל-אַבְרָם, חֲמָסִי עָלֶיךָ--אָנֹכִי נָתַתִּי שִׁפְחָתִי בְּחֵיקֶךָ, וַתֵּרֶא כִּי הָרָתָה וָאֵקַל בְּעֵינֶיהָ; יִשְׁפֹּט ה, בֵּינִי וּבֵינֶיךָ.
וַיֹּאמֶר אַבְרָם אֶל-שָׂרַי, הִנֵּה שִׁפְחָתֵךְ בְּיָדֵךְ--עֲשִׂי-לָהּ, הַטּוֹב בְּעֵינָיִךְ; וַתְּעַנֶּהָ שָׂרַי, וַתִּבְרַח מִפָּנֶיהָ.
"And he went in unto Hagar, and she conceived; and when she saw that she had conceived, her mistress was despised in her eyes.
And Sarai said unto Abram: 'My wrong be upon thee: I gave my handmaid into thy bosom; and when she saw that she had conceived, I was despised in her eyes: the LORD judge between me and thee.'
But Abram said unto Sarai: 'Behold, thy maid is in thy hand; do to her that which is good in thine eyes.' And Sarai dealt harshly with her, and she fled from her face."
Why is Sarah so indignant, that she says יִשְׁפֹּט ה, בֵּינִי וּבֵינֶיךָ, which implies Avraham did something wrong be abiding by this situation? And further, giving her as a maidservant back to Sarah is a strange resolution of the problem, though apparently the one Sarah sought.
If we look back at the Code of Hammurabi, we see the subsequent laws 146-147:
146. If a man take a wife and she give this man a maid-servant as wife and she bear him children, and then this maid assume equality with the wife: because she has borne him children her master shall not sell her for money, but he may keep her as a slave, reckoning her among the maid-servants.
147. If she have not borne him children, then her mistress may sell her for money.
Thus, giving birth to children does indeed raise the status of the maidservant, in that she may no longer be sold for money, but must be kept as part of the household when she wrongly elevates herself to full-wife status. However, she is not supposed to consider herself of equal or greater status than the wife, and if she does, the standard punishment is to be demoted back to maidservant.
This was thus Sarah's complaint - after bearing children, Hagar looked down at Sarah and considered herself an equal or greater. Avraham should then have demoted her to maidservant, in accordance with the dina demalchuta dina of the code of Hammurabi, so Sarah complains that he did not do what he should have. Avraham then complies with the law. Indeed, Hashem agrees with the ruling, and Sarah was correct in her complaint, for when Hagar flees, the angel of Hashem tells her (16:9):
שׁוּבִי אֶל-גְּבִרְתֵּךְ, וְהִתְעַנִּי, תַּחַת יָדֶיהָ.
'Return to thy mistress, and submit thyself under her hands.'
I don't necessarily agree with the following, but I thought I would mention it because it extends the Code of Hammurabi applicability into the current parsha, Vayera. I got the basic gist of it from Yonah bar Maoz, from the Department of Bible at Bar Ilan University. You can check out the dvar Torah in full here I am not doing justice to his full dvar Torah, and am only selecting out the portions I want and skewing them as I see fit and added some stuff of my own. So don't blame him for this, but check out his dvar torah at his website.
In Vayera, Sara demands that Avraham send away Hagar and her son. Bereishit 21:9-13:
וַתֵּרֶא שָׂרָה אֶת-בֶּן-הָגָר הַמִּצְרִית, אֲשֶׁר-יָלְדָה לְאַבְרָהָם--מְצַחֵק.
וַתֹּאמֶר, לְאַבְרָהָם, גָּרֵשׁ הָאָמָה הַזֹּאת, וְאֶת-בְּנָהּ: כִּי לֹא יִירַשׁ בֶּן-הָאָמָה הַזֹּאת, עִם-בְּנִי עִם-יִצְחָק.
וַיֵּרַע הַדָּבָר מְאֹד, בְּעֵינֵי אַבְרָהָם, עַל, אוֹדֹת בְּנוֹ
וַיֹּאמֶר אֱלֹהִים אֶל-אַבְרָהָם, אַל-יֵרַע בְּעֵינֶיךָ עַל-הַנַּעַר וְעַל-אֲמָתֶךָ--כֹּל אֲשֶׁר תֹּאמַר אֵלֶיךָ שָׂרָה, שְׁמַע בְּקֹלָהּ: כִּי בְיִצְחָק, יִקָּרֵא לְךָ זָרַע.
וְגַם אֶת-בֶּן-הָאָמָה, לְגוֹי אֲשִׂימֶנּוּ: כִּי זַרְעֲךָ, הוּא.
"And Sarah saw the son of Hagar the Egyptian, whom she had borne unto Abraham, making sport.
Wherefore she said unto Abraham: 'Cast out this bondwoman and her son; for the son of this bondwoman shall not be heir with my son, even with Isaac.'
And the thing was very grievous in Abraham's sight on account of his son.
And God said unto Abraham: 'Let it not be grievous in thy sight because of the lad, and because of thy bondwoman; in all that Sarah saith unto thee, hearken unto her voice; for in Isaac shall seed be called to thee.
And also of the son of the bondwoman will I make a nation, because he is thy seed.'"
Sarah wanted Hagar and her son out of the house, but they could not sell her, for as we saw earlier in the Code of Hammurabi, since she had born a son she could not be sold. Instead he is presumably freeing Hagar and sending her and Yishmael into the world to do as they please.
Why does Sarah want to eliminate them from the house. The Code of Hammurabi may again offer a clue. Recall Sarah said כִּי לֹא יִירַשׁ בֶּן-הָאָמָה הַזֹּאת עִם-בְּנִי עִם-יִצְחָק.
The Code of Hammurabi, Laws 170-171:
170. If his wife bear sons to a man, or his maid-servant have borne sons, and the father while still living says to the children whom his maid-servant has borne: "My sons," and he count them with the sons of his wife; if then the father die, then the sons of the wife and of the maid-servant shall divide the paternal property in common. The son of the wife is to partition and choose.
171. If, however, the father while still living did not say to the sons of the maid-servant: "My sons," and then the father dies, then the sons of the maid-servant shall not share with the sons of the wife, but the freedom of the maid and her sons shall be granted. The sons of the wife shall have no right to enslave the sons of the maid; the wife shall take her dowry (from her father), and the gift that her husband gave her and deeded to her (separate from dowry, or the purchase-money paid her father), and live in the home of her husband: so long as she lives she shall use it, it shall not be sold for money. Whatever she leaves shall belong to her children.
Thus, a father's recognition of the son of a maidservant as a son will entitle him to a portion of the inheritance. Lack of such acknowledgment would leed to lack of entitlement. Perhaps this acknowledgement can be retracted. But Avraham still recognized Yishmael as his son, as it stated "וַיֵּרַע הַדָּבָר מְאֹד, בְּעֵינֵי אַבְרָהָם, עַל, אוֹדֹת בְּנוֹ". Perhaps he retracted this recognition later.
(Although it is possible "beno" in this case was *Yitzchak* and not Yishmael, and Avraham was indeed troubled, as was Sarah, that Yitzchak would not get the full inheritance, in which case Hashem advises him to take Sarah's advice:
וַיֹּאמֶר אֱלֹהִים אֶל-אַבְרָהָם, אַל-יֵרַע בְּעֵינֶיךָ עַל-הַנַּעַר וְעַל-אֲמָתֶךָ--כֹּל אֲשֶׁר תֹּאמַר אֵלֶיךָ שָׂרָה, שְׁמַע בְּקֹלָהּ: כִּי בְיִצְחָק, יִקָּרֵא לְךָ זָרַע.)
Thoe Code of Hammurabi furthermore has more rules of interest in terms of sons, disowning, and inheritance, which precedes the above quoted law.
Code of Hammurabi 167-169
167. If a man marry a wife and she bear him children: if this wife die and he then take another wife and she bear him children: if then the father die, the sons must not partition the estate according to the mothers, they shall divide the dowries of their mothers only in this way; the paternal estate they shall divide equally with one another.
168. If a man wish to put his son out of his house, and declare before the judge: "I want to put my son out," then the judge shall examine into his reasons. If the son be guilty of no great fault, for which he can be rightfully put out, the father shall not put him out.
169. If he be guilty of a grave fault, which should rightfully deprive him of the filial relationship, the father shall forgive him the first time; but if he be guilty of a grave fault a second time the father may deprive his son of all filial relation.
The transition from #167 to 168 and 169 may suggest that the casting out from his house has an impact on inheritance, especially in light of what we saw later in 170 about the need for the father's calling of the child "son."
Thus, by kicking them out of the house, Avraham disowns them in terms of inheritance in a way that would be recognized legally in the society in which he dwelt.