Numerous people in jail or prison suffer very serious mental illnesses. A person in the throes of a schizophrenic psychosis cannot control what he or she does. He or she hears voices telling them what to do. A person in a severe mania is as "out of control" as can be imagined. Not their fault. They would be helped by having contact with family members. Better still, put into a theraputic (not penal) setting.
According to the National Institutes of Mental Health: 
Approximately 20% of state prisoners and 21% of local jail prisoners have “a recent history” of a mental health condition.
70% of youth in juvenile justice systems have at least one mental health condition and at least 20% live with a serious mental illness.
Only 41% of adults in the U.S. with a mental health condition received mental health services in the past year. 
We need to make it easier to get help for mental illnesses. Not using jails/prisons to warehouse these unfortunate citizens.