From a purely moral/ethical perspective, this doesn’t withstand scrutiny.
The foundational ideas underlying the justice system are inherently religious (in the literal sense) in that they depend on a world view that takes at face value the notion of free will, and assumes that all causal factors are under the control of the perpetrator.
The more we learn about the mechanics of the brain, the less we have a reason to believe in what people typically mean when they say someone did something freely and of their own accord.
This is not to say that people who do bad things shouldn’t be locked up for it. Negative consequences are still important. But the other things we attach to incarceration: retribution/revenge/punishment depend on dubious moral/ethical viewpoints that do not withstand scrutiny and are rooted in old religious moral dogma.
There is a category of brain malfunction that puts someone in the category of a “survivor” deserving our sympathy, support, and respect. And not long ago, those same survivors were looked at as social pariahs for the misfortune of being born with a deficient brain.
But when the malfunction (or collective systemic factors) leads someone to break the law, we’re predisposed to fall back to the deeply entrenched Judeo-Christian viewpoint that insists we are all free to make choices, and this freedom means the wrong choice is sin, and therefore a direct moral indictment.
Except the person who steals food out of necessity has no choice in the place of their birth. No control over growing up in economic circumstances that make it more likely they’ll get caught in the broken prison system. We can retroactively judge the person who deals drugs, but if everything else was equal and we had their brain, we’d have done the same thing.
And again, none of this means that serious crimes aren’t serious or that incarceration isn’t necessary, but we need to fundamentally shift the framing of why we do it, and what is or is not acceptable while doing it.