In 2000, a 40-year-old man was rushed to the University of Virginia Hospital emergency department while experiencing a severe headache. Perhaps he was faking it to escape the dire situation he had been in. In the previous year, he had developed an unusual increasing interest in porn, including child porn. While he had a pre-existing interest in porn dating back to his teenage years, he denied a previous attraction to children. He had been in a stable marriage for two years. He did not have a history of psychiatric disorders or prior deviant sexual behaviour.
Throughout the year 2000, he collected a large number of porn magazines and increasingly visited Internet porn sites to satisfy his obsession with child porn. He started soliciting prostitution which he had not done before.
He desperately concealed his activities but continued to act on his sexual impulses, completely unable to restrain his sexual urges. He even made subtle sexual advances toward his stepdaughter. She informed her mother and she discovered his preoccupation with child pornography.
He was removed from the home, found guilty of child molestation and was ordered to undergo rehab for sex addiction or go to jail. While in rehab, he solicited sexual favours from staff and other patients and was expelled.
Sixteen years earlier, he had had a head injury that left him unconscious for two minutes, followed by two years of migraines. During the neurologic examination, he solicited female staff for sexual favours and was unembarrassed when he peed on himself. He confessed he had had suicidal thoughts and rape fantasies. He complained of balance problems and an MRI scan was performed on him. An egg-sized brain tumour was discovered in his brain. Once it was removed, his sex obsession disappeared.
The tumour was located in the right lobe of the orbitofrontal cortex, an area of the brain responsible for inhibition, judgment and impulse control. It was the first case that brain damage was linked to paedophilia. While his knowledge of right and wrong was intact, the tumour had destroyed his control of sexual impulses.
Seven months after the tumour removal and completing the rehab program, he returned home. He complained of headaches and secretly collected porn again. An MRI scan revealed that the tumour had come back and after it was removed, his behaviour disappeared.
In another similar case, a 64-year-old well-respected pediatrician was caught while enacting sexually inappropriate behaviour towards a child in a kindergarten doctor’s office. He clearly had lost all judgment because his paedophilic urges were carried out in a risky manner leaving the office door wide open. His wife observed he had gradually changed with easy frustration and irritability followed by subtle behavioural disinhibition. His MRI scan revealed a large tumour that displaced the hypothalamus, which is responsible for sexual orientation and compressed the orbitofrontal cortex. After the tumour was removed, all the abnormal behaviour including paedophilic urges, disappeared.
These two cases raise an interesting question: to what extent are these two men culpable? Recent studies have estimated 25–87% of prison inmates suffered some sort of traumatic brain injury (TBI) in their life and indicated associations between TBIs and criminal-like behaviour.   TBI-related problems can complicate their management and treatment. They can experience mental health problems such as severe depression, anxiety, anger control issues, self-restraint, alcohol and substance abuse.
This makes it difficult for them to respond to disciplinary action in prison, to understand and remember rules, and anger issues can get them in dangerous incidents with other inmates. They also have a higher rate of recidivism.
The spirit of the law is that responsibility for a crime is reduced when a defendant’s cognitive ability is compromised by illness or injury. This means that people need to be tested soon after being arrested. Many people who are in prison shouldn’t be there due to this lack of diagnosis. There needs to be increased health screenings and rehab treatments and improved coordination between family, community mental health services, GPs and the school system. The justice system will have to move away from retribution and focus more on rehabilitation.
It doesn’t change the purpose of the justice system to reform their behaviour and provide safety for the rest of society. But the sentencing and treatment might have to depend on how modifiable their behaviour is. If a criminal is utterly beyond repair, brain damage or not, (s)he still needs to be locked away. But it might help many others who might benefit from treatment as the two examples in this answer.