Masturbation is haraam, as has already been explained in the answer to question no. 329; in Ramadaan it is even more haraam.
Masturbation, and also being intimate with one's wife and kissing her until semen is emitted invalidates the fast, and the one who does that has to repent to Allaah for doing this haraam action, and he has to fast a day to make up for the day which he spoiled, but he does not have to offer expiation (kafaarah), because expiation is only required for having intercourse during the day in Ramadaan.
Ibn Qudaamah said in al-Mughni (4/363): If he masturbates with his hand, he has committed a haraam action, but his fast is not invalidated by that unless he ejaculates; if he ejaculates then his fast is invalidated. End quote.
He also said (4/361): If he kisses (his wife) and ejaculates, then he has broken his fast and there is no difference of scholarly opinion that we know of. End quote.
Al-Nawawi said in al-Majmoo’ (6/349): If he kisses or engages in intimacy without having intercourse or touching the woman’s skin with his hand etc, then if he emits semen his fast is invalidated, otherwise it is not. Saahib al-Haawi and others narrated that there is scholarly consensus that the fast of one who kisses or touches his wife, without having intercourse, then ejaculates, is invalidated. End quote.
It says in Bidaayah al-Mujtahid (1/382): All of them – i.e., the imams – say that whoever kisses and ejaculates has broken his fast. End quote.
Ibn ‘Abd al-Barr said in al-Istidhkaar (3/296):
I do not know of any scholar who granted a concession with regard to kissing for the one who is fasting, unless he is confident that nothing will result from that; for the one who knows that it will result in something that will invalidate his fast, he must avoid that. End quote.
Shaykh Ibn ‘Uthaymeen said in Fataawa al-Siyaam (p. 237): It is not permissible for a man to engage in foreplay with his wife if he knows that he will ejaculate as a result of that, because some people are quick to ejaculate just by engaging in foreplay, or kissing a woman and so on. So we say to such a man: it is not permissible for you to engage in foreplay with your wife so long as you fear that you may ejaculate. End quote.
He also said in al-Sharh al-Mumti’ (6/234-235):
If he seeks to expel semen by any means, whether by hand or by rubbing it on the ground and so on until he ejaculates, then his fast is invalidated by that. This is the view of the four imams (may Allaah have mercy on them), Maalik, al-Shaafa’i, Abu Haneefah and Ahmad.
The literalists (al-zaahiriyyah) rejected that and said: the fast is not invalidated by masturbation even if one ejaculates, because there is no evidence from the Qur’aan or Sunnah that the fast is invalidated thereby, and an act of worship cannot be ruled to be invalidated unless there is evidence from Allaah and His Messenger (peace and blessings of Allaah be upon him). But in my view – and Allaah knows best – we may understand that it does break the fast on the basis of the following two points:
1 – From the texts. In the saheeh hadeeth it states that Allaah, may He be glorified and exalted, says concerning the one who fasts: “He gives up his food, his drink and his desire for My sake,” and masturbation is a kind of desire, and emission of semen is a kind of desire. The evidence that semen may be described as desire is the words of the Messenger (peace and blessings of Allaah be upon him): “In the intimacy of one of you there is charity.” They said: “O Messenger of Allaah, if one of us fulfils his desire, is there reward in that?” He said: “Do you not see that if he fulfils it in a haraam manner, he will bear a burden of sin? Similarly, if he fulfils it in a halaal manner, he will have reward.” And what is referred to here is semen.
2 – Based on analogy. We say that the Sunnah states that a person breaks his fast by making himself vomit if he vomits, and he breaks his fast by cupping if he is treated with cupping and blood comes out of him. Both of these weaken the body.
As for the emission of food, it is clear that this weakens the body, because the stomach remains empty and the person will quickly become hungry and thirsty.
With regard to the emission of blood, it also seems that it weakens the body, and the same results from emission of semen, which undoubtedly exhausts the body. Hence there is the command to do ghusl, which restores energy to the body, and this is by analogy with cupping and vomiting.
Based on this we say: if semen is emitted with desire, then it invalidates the fast, on the basis of the texts and analogy. End quote.
Based on these two points – the fact that it is fulfilment of desire and that it weakens the body, Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) ruled that masturbation invalidates the fast. See Majmoo’ al-Fataawa, 25/251.
Shaykh Ibn Baaz (may Allaah have mercy on him) said:
Masturbation during the day in Ramadaan invalidates the fast if it is done deliberately and semen is emitted as a result. The person has to make up that fast as an obligation, and he has to repent to Allaah, may He be glorified and exalted, because masturbation, which is what people call the ‘secret habit’, is not permissible whether one is fasting or otherwise. End quote.
Majmoo’ Fataawa Ibn Baaz, 15/267
The scholars of the Standing Committee for Issuing Fatwas (10/256) said:
Masturbation during Ramadaan and at other times is haraam and it is not permissible to do it, because Allaah says (interpretation of the meaning):
“And those who guard their chastity (i.e. private parts, from illegal sexual acts)
6. Except from their wives or (the slaves) that their right hands possess, __for then, they are free from blame;
7. But whoever seeks beyond that, then those are the transgressors”
The one who does that during the day in Ramadaan when he is fasting has to repent to Allaah and make up the fast of the day when he did that, but he does not have to offer expiation (kafaarah), because expiation is required only in the case of intercourse. End quote.
And Allaah knows best.