this is why we have a broken system
it's meant to work so that true cause of crime being mental illness should be dealt with in the right way, treatment of mental illness should be treated in the right way, therefore there's never a conflict between punishment and treatment even if if during a sentence someone develops a mental illness - there are already grounds to keep people locked up on mental heath reasons for longer than/independently to sentencing.
fifty years isn't a life sentence, it's a fifty year sentence, if that was fit for the crime is a different debatable point to being mentally fit to serve the time, or if mental treatment counts to the sentence time served, or if secure mental treatment (potentially for actual life) is a valid action to take.
the reality is all too often 1 of the following
1. diminished mental grounds = locked up for an inappropriate length of time unrelated to the crime/sentence with no treatment and therefore no chance to ever get free even if they had served their time
2. sentenced with no mental health support when it's needed
3. inappropriate sentencing either via interpretation or poor guidelines
only 1 thing is clear, everyone gets fucked over, the public, the victim and the person with mental health issues
piss poor