If retrospective change is a problem then maybe modify things. Let them go at the allotted time, from at the time of the offence, and afterwards take them to a place where, for their own sake, they can be monitored over an additional period to help them not feel a need to harm others in society. Perhaps some kind of asylum. Since this would be a new law that wouldn't trigger until someone leaves gaol, it isn't part of any existing punishment. It's simply compulsory for their own benefit; and for society's too, as it happens.