Is he able, but not willing? Then he is malevolent.
Is he both able and willing? Then whence cometh evil?
Is he neither able nor willing? Then why call him God?
Epicurus
God gave us free will.
It means that we have capacity to do good or evil.
If God prevent us to do something, he block our free will and freedom.
Without our freedom we will be just like robots and God don't want it.
So, God have no choice but to allow both good and evil in this world, so that people can learn from their suffering and return to him, like in the story of ''Prodigal son'' in the Bible.
God acts with us in all our freedom and liberty He gave us.
Everything acts according to cause and effect. This means that everything is programmed, and that there is no free will.
But, God, Himself, holds open a tiny bit of freedom in us regarding how much we believe in Him. Then He regulates our lives in ways that match our faith in Him. We think that it was our free will, when what it was, was, God interpreting our faith in Him, and adjusting our lives according to our faith.