brains are organs that influence our behavior when meddled with. they can perform many tasks through their individiual parts, while free will more or less can just choose how to make use of these parts, if at all.
if the brain is impaired in some way (and scans show measurable differences of mentally ill brains compared to neurotypical ones), then it will limit the scope of what your free will can work with.
so to speak, you can order yourself to stop being a shitty person, but it takes time and work to rewire your habits and behaviors because they exist on a physical part of yourself.
adequately punishing a person for shitty behavior simply helps with that process (at least for the onlookers), because the brain tends to prefer not expending energy to reform itself when it is not seen to be necessary.