In Genesis 21:14, Abraham sends away his child, not because he wants to, but because God tells him to (21:12-13). In fact, sending away his son distressed him greatly (21:11) and he only did it after God promised to make his son into a great nation (21:13), which is another way of saying he would survive. This is interesting because we don’t see Abraham distressed when he’s told to sacrifice Isaac.
Anyway, if I were writing the story, I might say that Abraham sent Ishmael away, and he later became a bowman. But the Torah goes into painful detail about what happened next. Ishmael and Hagar suffered immensely; baby Ishmael was on the brink of dying of thirst. Why does the Torah include this part of the story? After all, it is painful to read, and we know Abraham did the right thing according to God.
An explanation I’d like to offer is that there’s a lesson for us: even when you do the right thing, it may cause immense suffering in the short term. When that happens; don’t look away.