CCC 311 Angels and men, as intelligent and free creatures, have to journey toward their ultimate destinies by their free choice and preferential love. They can therefore go astray. Indeed, they have sinned. Thus has moral evil, incommensurably more harmful than physical evil, entered the world. God is in no way, directly or indirectly, the cause of moral evil.1 He permits it, however, because he respects the freedom of his creatures and, mysteriously, knows how to derive good from it:
For almighty God. .., because he is supremely good, would never allow any evil whatsoever to exist in his works if he were not so all-powerful and good as to cause good to emerge from evil itself.2

1 Cf. St. Augustine, De libero arbitrio 1,1,2: PL 32,1221-1223; St. Thomas Aquinas, STh I-II,79,1.
2 St. Augustine, Enchiridion 3,11: PL 40,236.