Insanity is probably the most known mental health related defense for criminal cases, but mental health can be used in other ways as a defense to your criminal charges.
For example, a claim of self defense asks the jury to see the situation from your point of view. Someone with severe PTSD is going to react differently in a situation that involves self defense than someone who has not had a similar traumatic experience.
Also, there are moments in the arrest process and court proceedings where you receive written advisements and waivers of your rights. A learning disability or developmental issue can have a huge impact on whether or not you understand your rights and the impact of waiving them.
Speaking with an experienced criminal defense attorney about your mental health can help you create the best defense to your criminal charges.