We may conclude from all this that the punishment is bad, and it is the opposite of what is desired and intended by the Supreme Will. However, it exists as a necessary means through which His creatures attain the end goal. If it were possible to attain the end goal without this means, it would have been better, given that His will is for good. Just as inflicting punishment in individual cases is the opposite of His will – which is why it must eventually come to an end – so too we may infer that punishment in general in the running of the world is also against the Supreme Will, and must change in the end.
Is Punishment Good When It Guides a Child to Grow
Kalach Pitchei Chokhmah 2:9