Hazrat Shaikh Moulana Muhammad Zakariyya (rahmatullahi ‘alaih) once mentioned the following advice in a letter he wrote to a certain person who was suffering from doubts and stray thoughts and was also contemplating suicide:
An effective remedy for dealing with doubts and stray thoughts is for one to ignore the doubts and stray thoughts and not pay any attention to them.
Furthermore, one should recite ‘Laa howla walaa quwwata illaa billaah’ forty-one times after every fardh salaah, together with reciting durood shareef before and after.
I am disappointed and grieved that an intelligent person such as yourself has been getting thoughts regarding committing suicide. To even contemplate suicide is a sin, hence you should not even think about it. May Allah Ta‘ala bless you with aafiyah (ease).
(Qutbul Aqtaab Hazrat Shaikhul Hadith Moulana Muhammad Zakariyya [rahmatullahi ‘alaih] pg. 427)
Source: Ihyaauddeen.co.za