HHS.gov write about mental health:
Mental health includes our emotional, psychological, and social well-being. It affects how we think, feel, and act. It also helps determine how we handle stress, relate to others, and make choices.
... Many factors contribute to mental health problems, including: (a) Biological factors, such as genes or brain chemistry, (b) Life experiences, such as trauma or abuse, and (c) Family history of mental health problems.
Poor mental health and mental illness can lead to negative consequences, such as suicide and self harm, along with other unsocial behaviors, e.g. drug use, excessive drinking, excessive dieting, gambling, and so on. Included in this list are behaviors strongly forbidden in Islam (i.e., they're major sins).
Question: Is mental health treatment sufficient to make permissible otherwise haram acts?
It's widely accepted in Islam that necessity overrides prohibition (الضـرورات تبیح المحظورات) provided there is no alternative, e.g.:
...If a forbidden insulin is the only choice, a religious leader or doctor should be encouraged to mediate and reduce the patient's guilt feeling and spiritual pain. These advisers would use the doctrine of ‘the sanctity of life’, permissible in Islam. It means that life must be saved at all costs. -- Bashir Qureshi, Diabetes in Ramadan, J. R. Soc. Med. 2002.
While mental health treatment can be life saving, it doesn't usually take the immediate form "undergo treatment X and you'll be cured". Personal friends who have taken antidepressants report a "trial and error" nature, i.e., we can't know in advance whether a treatment works for a particular patient (if it doesn't work, try another medication). So it's not obvious that "necessity overrides prohibition" applies to mental health treatment. Likewise, I'm uncertain whether mental health treatment falls under the umbrella of the hadith:
Two prominent examples of conflict I've found in the medical literature are: (a) Muslims not taking medication during Ramadan, and (b) Muslims refusing to take medicine involving pork products. For example:
As ingestion of pork or any of its products is totally forbidden in Islam and it may be considered as committing a sinful act. So if this issue is not identified and addressed, then patients may not only stop taking their medications, and hence leading to relapse of symptoms, increasing hospitalization rates, and increasing healthcare costs but also lead to a poor doctor-patient relationship. -- Sabry and Vohra, Role of Islam in the management of Psychiatric disorders, Indian J Psychiatry. 2013.
Also, surveys report unwillingness of Muslims to acknowledge and seek treatement for mental health issues (interpreting them as e.g. tests from God, or possession by jinn):
Even when Muslims have positive attitudes toward mental healing, social stigma remains strong. -- Ciftci, Jones, and Corrigan, Mental Health Stigma in the Muslim Community, Stigma, 2012.
This question arose as a result of Medi1Saif's answer to How does harm to honour and reason fall under the adage "necessity make forbidden things permissible"?.