I highly recommend watching Jordan Peterson's lectures on youtube called "Biblical Series". They (attempt to) explain this and similar questions from Christianity to people who are typically smart and approach the world intellectually, who will usually have trouble with these concepts and the meaning of the stories.
Regardless of "belief" in Christinity, it is clear to me at least that any such simplistic interpretation as "god was just a dick", is at the very least, missing the point of the stories. There is a much more deep and logical meaning in many of those stories, which becomes very obvious when you get presented to it, and that's before you even start tapping into the spiritual/existential/metaphysical content of the stories. It makes much more sense even as simple life wisdom.
To present an overly simplified answer, I will say that typically (and this is a typical occurrence in the stories, where god does something painful or creates an obstruction), when something like that happens, the phrase "god did it", does not refer so much to the fact that christinaity tries to make up this god character and give him some lines to make him look a certain way, in order to tell some message.
Instead, "god did it this way" refers to god being everything, the universe, including the human societies: god is not something above human world as a guy in the sky (in fact bible never presents that image, it's more something from monty python), god is the personfification of the world and everything that happens in it.
And what happens in it is that sometimes people feel pain, do stupid things, sometimes tragical (appearing so) events happen. That's just the fact of life. Christianity does not triumphantly claim that "god did it" as any form of justification, it simply describes that since those thing do obviously happen, that means the universe, the world, the society - the god (all those things combined) make those things happen. And then the rest of the story is presented in such a way as to understand how humans can act in relationship to those underelying realities. How they can respond to and understand what is happening in the world.