This question is usually framed in relation to the God of love.  If God is good and loving, why would He allow evil in the world?

In order to understand the answer to this question, one has to understand the eternal nature of people, the universality of the principle of liberty, and the purpose of this world.

A person has an “essence” that has always existed.  This “essence” of you was not created and cannot be destroyed.  Your “essence” was embodied in a spirit in the celestial realm.  You are a child of God. You were then given the opportunity to be born on earth where your spiritual self was incorporated into a physical body. So here we are the “essence” of ourselves in a spirit body which is in a physical body.

God abides by the principle of liberty which is that everyone has the right to decide what to do with themselves and their possessions. This is referred to as agency in the Church of Jesus Christ of Latter-Day Saints. Agency meaning that each person is an agent unto themselves. Now God created this earth and everything in it including our bodies, so He has a property right for all this.  God does not have a property right in that “essence” of each person which we manifest by our will or our ability to choose what we will do. God will not force a person to do something against their will.

God sends us into this world and disables our memory of our previous existence.  The purpose is to see what we will choose given our liberty and being on our own.  God only allows those who choose good to live where He lives.  God prepares other places for those who choose lessor degrees of goodness.  The choice between good and evil must be real.  Consequently, there is evil in the world.

God does everything in His power to invite, entice, and encourage people to choose the good, but He will not violate anyone’s agency.  God may exercise His property right and decide in His wisdom that it is better for all concerned if a person or a people are taken out of the world.  The most obvious example of this is the flood where everyone except Noah and his family were so corrupt that most people being born had little chance of learning to choose the good.

God abhors evil and ensures that it is contained.  God allows evil in this temporary abode so we can have the opportunity to show our willingness to choose the good and be able to live with God again.