Plenty of Blame to Go Around
In the drama which unfolds in Genesis 21, there is certainly plenty of blame to go around. If you tend to root for the underdogs, who in this case are Hagar and Ishmael, your heart goes out to them. Abraham had every right to be upset with his wife Sarah for her obvious harshness and indifference toward Hagar ("that slave woman," as Sarah referred to her) and her son Ishmael, whom Sarah had caught either mocking her son Isaac or playing with him as if he were on equal footing with the child of promise, which he was not (Genesis 17:19, NET footnote 17).
Abraham (and Sarah, for that matter) was certainly reaping what he had sown. He had inadvisably listened to his wife in the matter of having a son by Hagar, Sarah's Egyptian maid/slave, and the conflict which ensued was both unnecessary and obviously preventable. As the young people say nowadays, however, "it is what it is."
Sarah was equally to blame for her insistence that Abraham have a son by Hagar (not that Abraham needed that much persuading to have sex with an attractive woman who was probably much, much younger than Sarah!). Had both she and Abraham listened--really listened--to the promise God had made to them in Genesis 17:19 and 18:10, they would not have been in the pickle in which they found themselves in Genesis 21.
Ya' Reaps What Ya' Sows
In the matter of reaping and sowing (see Galatians 6:7-8), there is bound to be unpleasant fallout. God was not, as you suggest, "on Sarah's side" in the matter of Hagar and Ishmael. In a sense, Sarah was behaving quite naturally, since she was guarding zealously the rights and privileges accruing to her son by virtue of his status as the heir apparent. You can rest assured that Abraham expressed his outrage to his wife Sarah for being so heartless and unfair.
God calmed Abraham down, however, and assured him that Hagar and his beloved firstborn had a bright future ahead of them (Genesis 21:13). Moreover, God came to their rescue when Hagar, despairing of her life, cried in God's hearing, and he repeated to her the promise he had made to Abraham that Hagar's son would become a great nation one day (v.18).
And Now, From God's Perspective . . .
Notice I italicized the word his in my last paragraph. I did so because while Ishmael was Abraham's firstborn, God did not consider him Abraham's firstborn! In fact, in Genesis 22, here is what God said to Abraham:
"'Abraham . . . take now your son, your only son, whom you love, Isaac, and go to the land of Moriah, and offer him there as a burnt offering on one of the mountains which I will tell you'" (excerpted from vv.1-2, with my emphasis).
From God's perspective (which should have been Abraham's perspective too), Isaac was Abraham's only son. After all, God had promised Abraham and Sarah a son in their old age. Sarah and Abraham, however, had wavered in faith by taking matters into their own hands in an attempt to "help God." God, of course, needed no helping hand in doing what to them had seemed impossible (see Genesis 18:14).
Appearances Can Be . . . Deceiving
In conclusion, while God may appear to have sided with Sarah, in reality he did not. He graciously gave the child of Sarah's handmaid a bright future by first saving him from a certain death in the wilderness, and then by allowing Ishmael to grow into a skilled hunter who eventually married "one of his own" (an Egyptian) and become a father many times over.
As Sir Walter Scott said (Marmion, 1808), "What a tangled web we weave, when first we practice to deceive." In the affair of Abraham, Sarah, Hagar and Ishmael, there may not have been an intent to deceive, but there was certainly an attempt to perform an "end run" around God. We reap what we sow, and our tangled web is of our own making!
Regardless, God still has the last word!