This question already has an answer here:
The Halacha is well-known: in general, one violates Torah prohibitions in order to save a life. I will specifically focus on Shabbos in this question, but the question can probably be extended if I can think of a relevant case.
I see that the Shevet HaLevi (Shu”t 8:65) discusses a case where a critically ill person who asks for something to be done, and if it’s not his stress levels will increase, leading to things such as higher blood pressure, etc., which, for someone in his condition, could be life-threatening. He paskens that if there is a strong indication that he will die as a result of his wishes not being heeded, then one may do so (“יש רגלים לדבר שיכול לצמוח מזה ספק פקוח נפש״). Barring that, one may ask a non-Jew to perform the action for him.
What is the Halacha regarding one who is suicidal? If someone is known to be suicidal, and he needs his medicine, which requires carrying through a reshus harabim (let’s say, and let’s say further that, for whatever reason, the patient can’t get it himself). Can this be compared to the Shevet HaLevi, in that it’s a psychological/emotional issue that leads to his death, or perhaps it’s different, in that the Shevet HaLevi’s case it happens on its own for physiological issues, whereas in this case it’s directly caused by the patient, with the psycholigical issues being the motivation rather than a direct cause?