There is a novel, and damned if I can remember the title, where a rabi proposes that god commanding Abraham to kill his son was a test, which he (Abraham) failed.
The implication I’m making is that a moral deity that allows free will might allow bad things to happen as a test for people to act morally. Religion, instead has been at the root of problems and/or stood by while bad people do bad things.