It’s a medieval idea that crime needs to be punished? Did I read that right?
Yes, you did. It's the Medieval idea that punishing by itself makes it even out in the eyes of God.
Punishment directly doesn't work. Reacting to the crime afterwards won't do the victims any good, all too obviously.
Punishment as a deterrent doesn't work. There's always someone who want's to try nevertheless.
You're not trying to punish, you put them away, some with the hope of correction, some with just keeping them locked in from harming people.
The correction rates, as in people who don't repeat the crime after their first sentence, are good enough to justify the approach.
Repeat offenders, different story. Career criminals or organized crime, yet another story. Strong measures warranted.
None of what works in the above has anything to do with silly "punishment!" as a solution. It doesn't reduce crime. Other measures do.