Sometimes failure comes from inherent risks. Sometimes we don't know what we don't know. You can't account for every possible factor, you'll be stuck in analysis paralysis while the world moves on.
If we're speaking of a justice system in more general terms, I agree with your line of thinking. I believe that repairing the damage and reintegrating with society would be far more effective than incarceration or other forms of punishment. Fear is a seed, you reap what you sow.
(Yes there are extreme cases. Still the long-term goal should be to minimise harm, not bring punishment.)