God’s permission of evil in the things governed by Him is not inconsistent with the divine goodness. For, in the first place, the function of providence is not to destroy but to save the nature of the beings governed. The perfection of the universe requires the existence of some beings that are not subject to evil, and of other beings that can suffer the defect of evil in keeping with their nature. If evil were completely eliminated from things, they would not be governed by divine providence in accord with their nature; and this would be a greater defect than the particular defects eradicated.
Secondly, the good of one cannot be realized without the suffering of evil by another. For instance, we find that the generation of one being does not take place without the corruption of another being, and that the nourishment of a lion is impossible without the destruction of some other animal, and that the patient endurance of the just involves persecution by the unjust. If evil were completely excluded from things, much good would be rendered impossible. Consequently it is the concern of divine providence, not to safeguard all beings from evil, but to see to it that the evil which arises is ordained to some good.
Thirdly, good is rendered more estimable when compared with particular evils. For example, the brilliance of white is brought out more clearly when set off by the dinginess of black. And so, by permitting the existence of evil in the world, the divine goodness is more emphatically asserted in the good, just as is the divine wisdom when it forces evil to promote good.
Thomas Aquinas, Compendium Theologiae, Chapter 142.