Ruling on fasting for one who is forced to masturbate
If this brother’s situation is as you describe, then the ruling is that of one who is forced to break the fast. The view of the Shaafa‘is and Hanbalis is that in the case of one who is forced to break the fast by having intercourse, eating or drinking, if the one who is forced does that, it does not break the fast and he does not have to make it up, unless the compulsion to break the fast was by means of zina, according to the Shaafa‘is. (al-Mawsoo‘ah al-Fiqhiyyah, 28/58).
This view is the closest to what was narrated by Ibn ‘Abbaas (may Allah be pleased with him), that the Prophet (blessings and peace of Allah be upon him) said: “Allah has pardoned my ummah for mistakes, what they forget what they are forced to do.” Narrated by Ibn Maajah (2045); classed as saheeh by al-Albaani in Takhreej al-Mishkaat (6248). And because in the case of compulsion there is no choice, and it is worse than forgetting, and the one who forgets does not break his fast according to the correct view, then being forced to break the fast is less serious than being forced to utter words of kufr, and the one who utters words of kufr under compulsion does not become a kaafir.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: If a person is forced to do anything that breaks the fast and does it, there is no sin on him and his fast is still valid, because Allah, may He be exalted, says (interpretation of the meaning): “And there is no sin on you if you make a mistake therein, except in regard to what your hearts deliberately intend. And Allah is Ever OftForgiving, Most Merciful” [al-Ahzaab 33:5]. And because Allah has ruled that no one is a kaafir who is forced into kufr, so with regard to that which is less serious than that, it is more apt that there should be no sin on them. And because the Prophet (blessings and peace of Allah be upon him) said: “My ummah has been pardoned for mistakes, what they forget what they are forced to do.”
End quote from Majmoo‘ Fataawa al-Shaykh Ibn ‘Uthaymeen, 19/207
We ask Allah, may He be exalted, to heal your friends and grant him well being. We advise him to persist in performing ruqyah, offering a great deal of supplication (du‘aa’) and giving charity, because these are the means of healing and relieving calamity. Also remind him to be patient and seek reward with Allah, because Allah, may He be glorified and exalted, tests His slave with whatever He wills, to expiate his bad deeds or raise him in status. The Prophet (blessings and peace of Allah be upon him) said: “Nothing befalls the believer of disease, affliction, distress, grief or harm, even a thorn which pricks him, but Allaah will cause it to expiate some of his sins.” Narrated by al-Bukhaari (5642) and Muslim (2573).
And Allah knows best.