That is a big question that lots of people have wrestled with. Leibniz called it a theodicy, and I can offer a variety of suggested reading. TLDR: The Christian view tends to be that human freedom to choose has to include the possibility of evil. Here’s a general take from a favorite source, the New Dictionary of the History of Ideas: bit.ly/bc-theodicy1. For a more Catholic view: bit.ly/bc-theodicy2. and for a classic more popular treatment, “When Bad Things Happen to Good People”: bit.ly/bc-theodicy3.