God meant it for goodness
In Genesis 50:20, this signifies to turn their temptations into good, for what God intends, He performs. (Arcana Coelestia 6572)
Acts 7:19
19
The same dealt subtilly with our kindred, and evil entreated our fathers, so that they cast out their young children, to the end they might not live.