The thing is, whether the people who commit these sort of crimes have been abused themselves, whether they are brain damaged, mentally ill or what-have-you, is an aside.
The fact is that people who commit these types of crimes - sexual abuse, rape, violence towards vulnerable - are wired to commit these sorts of crimes. I know with child sex offenders there is a very high chance of reoffence, I would imagine the same is true of rapists and those who like to hurt people who are vulnerable.
They are a different sort of crime from burglary/drug dealing/mugging etc where there are underlying causes (often drug addiction/lack of education so unable to work etc) where the underlying cause can be addressed and the criminal rehabilitated.
IMO (and I am generally a liberal lefty type too) these people are bloody dangerous, and given the reoffence rate should be kept away from society, whether in prison or secure hospitals or other places, until there is zero chance of the committing another crime.
Because the nature of the crime is just so awful that the merest chance that the person will reoffend should mean they are kept away to keep people safe. And because if a person is a psychopath, and they have no empathy, and enjoy violence, then where is their reason not to do it again?
The safety of the public must be paramount in these cases. But it seems to me it's only the cases where there is public outcry where very long/indefinite sentances are imposed.