There are a number of different ways to answer the problem of evil. These are called “theodicies.”
Probably the most famous is the Free Will Theodicy: God permits evil because it is good for him to respect the free will of the creatures he endowed with free will.
Evil is not a substance. Evil is the lack of a good that should be present. Thus, everything God created is good and God only wills good. However, God’s creatures with free will can choose lesser goods over higher goods. Thus, I could choose the good of sleeping over the good of going to work and providing food for my family. That is evil because I have corrupted the priority of goods.
God permits evil because he can bring good even out of evil in ways that we can’t imagine. God himself, however, does not intend evil actively but only permits it.