Mental illness is relevant as a defensive theory and a mitigation of punishment.  If a person was insane at the time of the offense, they could be found not guilty by reason of insanity.  If they were legally sane, but have mental health issues, many judges in Texas will order mental health treatment as a condition of probation.  Some counties even have specialized diversion programs just for people with mental health issues.