We ask Allah to heal this sick person from this sickness that he is suffering, and we ask Him, may He be glorified, to guide us and him to the truth and the right path, for He is able to do that.
The conditions of accountability with regard to commands and prohibitions are being an adult and being of sound mind. When a person becomes an adult of sound mind, it becomes obligatory for him to do what is enjoined of praying, fasting, giving zakaah, performing Hajj and other obligatory duties, and he is also obliged to avoid things that are prohibited.
It says in Fataawa al-Lajnah ad-Daa’imah (vol. 2, 6/370): Prayer is obligatory upon the individual and is not waived under any circumstances so long as he is of sound mind, because the conditions of accountability are being an adult and being of sound mind. The command to pray is not waived because of loss of a limb or physical faculty, or because of sickness, or similar problems, because of the general meaning of the Qur’an and Sunnah, and scholarly consensus to that effect. But if a person suffers some physical harm and is not able to do all the obligatory actions and essential parts of the prayer, then he may pray according to what he is able to do. End quote.
Based on that, if this mental illness does not affect the person’s reasoning or consciousness, as appears to be the case in the situation mentioned, then it is obligatory for him to pray and fast, because he is still accountable.
But if he loses his mind sometimes, and is of sound mind sometimes, then he is excused at the times when he loses his mind, but when he comes back to his senses the excuse is no longer applicable, and he has to offer the prayer that is currently due and make up the prayers that he missed during the time when he lost his mind.
What you must do is advise this man and remind him of the great importance of prayer and fasting, and tell him that the one who does not do these duties without any excuse is in grave danger; in fact keeping away from remembrance of Allah is one of the greatest causes of mental illness, as Allah, may He be exalted, says (interpretation of the meaning):
“But whosoever turns away from My Reminder (i.e. neither believes in this Quran nor acts on its orders, etc.) verily, for him is a life of hardship”
Allah, may He be glorified, also tells us of the means of attaining peace of mind, as He says (interpretation of the meaning):
“Verily, in the remembrance of Allah do hearts find rest”
[ar-Ra ‘d 13:28].
It should be noted that the individual is responsible for all of his deeds before his Lord, may He be glorified and exalted, so long as he is aware of what he is saying or doing. His illness is not an excuse for him to commit whatever sins he wants, such as neglecting the prayer, backbiting and spreading malicious gossip. … The individual has no argument against his Lord, may He be glorified and exalted; rather Allah has the perfect proof and argument against all His creation.
We ask Allah to set the affairs of the Muslims straight and to bring them back to Him.
And Allah knows best.