I Upvoted @StrangeLoop's excellent answer. I did want to point out that the law is applied unevenly across the United States.
Are people ever exempted from prosecution for being a$$holes? Absolutely. The California Highway Patrolman who beat the homeless woman trying to cross the highway was supported by his commander (I haven't heard the latest; I know she's suing.) The video is here. The CHP beat her up to "protect her from injuring herself". Read about police killing mentally retarded, unarmed teenagers, little old ladies, etc.
Most people in prison have a mental illness called Conduct Disorder. The key deciding factors in prosecution of people with mental illness are 1. does the person know right from wrong, and 2) can they control their behavior. In Conduct Disorder, the answer is yes to both.
There was a fascinating case in the news of an epileptic who had a part of his brain removed to control his seizures. After the surgery, he began to buy pornography, then child pornography. Neurosurgeons testified that the part of the brain they removed was indeed responsible for this predilection, but because he knew better than to put the porn on his work computer, he was judges to be in charge of at least some of his behavior. He got half the usual sentence and drugs have rendered him back into the nice guy he was before (and he really was. You can listen to his story on Radiolab.)
An entire field called neurolaw has cropped up to deal with how the law should treat criminals with neurological conditions.
To answer your original question, many people with bad personality traits have mental disorders. Borderline Personalities drive people crazy. So do kids with Oppositional Defiant Disorder. These people, as long as they are "rational" aren't spared from the law (Jodi Arias, for example, probably suffers from Borderline Personality Disorder. Still, she knew killing someone wasn't really a reasonable option.)
Andrea Yates, though, suffering from severe post-partum depression with psychosis, really believed that the only way to "save" her children from hell was to drown them. The most responsible person in that case - her husband - got off scott-free. (He was warned after her PPD/P with her fourth child that she should never get pregnant again. He wanted a basketball team of children (he actually said this). He stopped her psychiatric visits and meds, got her pregnant again, and in the midst of her psychosis, even though she admitted she felt the need to kill her children (which his family and the psychiatrist she was seeing knew; he stopped those visits, too), he left her alone with the kids.
Th point is the law (courts) is not consistent or even consistently necessarily rational. Often, though, it does the right thing.