Ramadan is the month of mercy, forgiveness and seeking protection from the hellfire through various acts of worship. It is a special month in the sense that we are supposed to make the best use of our time to draw closer to Allah the Almighty by doing good deeds and staying away from bad deeds. We should focus on reciting the Qur’an, praying taraweeh, giving charity, making dhikr (mention of Allah) and istighfar (seeking forgiveness for one’s sins), etc.
The wise Muslim is he or she who never misses any good in Ramadan. In an authentic Hadith the Prophet (peace and blessings be upon him) is reported to have said: “Truly is lost whoever hears my name and does not invoke blessings on me; truly is lost whoever catches Ramadan and he misses the chance to get his sins forgiven; truly is lost whoever catches his parents in their lives until they become old, and yet he misses to attain Paradise (through honoring and taking care of them).” [At-Tirmidhi, Sunan, Vol. 5, Hadith no. 3613; this Hadith has been classified as hasan saheeh (good and authentic) by Sheikh Al-Albani in his book Saheeh At-Tirmidhi, Hadith no. 2810].
That is why a Muslim should not only avoid the haram during Ramadan, but should not even think of it, as he or she is supposed to be involved in `ibadah (worship) and increasing his or her good deeds.
As far as masturbation is concerned, we are required to avoid it at all times and not only in Ramadan.
With regard to whether masturbating while fasting breaks the fast or not, Sheikh Hamed Al-Ali, instructor of Islamic Heritage at the Faculty of Education, Kuwait and Imam of Dahiat As-Sabahiyya Mosque, says:
“Masturbation during the daytime of Ramdan breaks the fast, based on the Hadith that a fasting Muslim gives up eating, drinking, and sexual desire for the sake of Allah. Since masturbation is a kind of sexual desire, a fasting Muslim must avoid it. The Prophet’s (peace and blessing be upon him) mention of “sexual desire” after “eating and drinking” is evidence that it breaks the fast if one does fulfill his or her sexual desire during the daytime of Ramadan. Therefore, masturbation does invalidate the fast, as it is one of the sins that if someone does it he or she would be violating the sanctity of this month.”
Also, in the Egyptian Encyclopedia of Fatwas, it is stated that:
“According to the followers of the Hanafi School of Fiqh, masturbation does not break the fast if no ejaculation occurs; however if someone masturbates while fasting and this ejaculates sperm (or sexual vaginal secretions in the case of women), his or her fasting is broken and he or she has to make up for that day.”
Sheikh Muhammad Iqbal Nadvi, Imam of Calgary Mosque, Canada, and Former Professor at King Saud Univ., Saudi Arabia, adds:
“If someone masturbates while fasting, his or her fasting is broken, and he or she has to make up for that day later on. The reason is that the release of sperm (or sexual vaginal secretions in the case of women) comes as a result of desire and sexual excitement, which is haram during the daytime of Ramadan.
We know that scholars said if someone vomits by intention it will break the fast but if he vomits unintentionally it will not break the fast. If we apply the rule of qiyas (analogy) to this case, we would say that if someone releases sperm (or sexual vaginal secretions in the case of women) due to a sexual (wet) dream or without desire, it will not break the fast. However, if he or she intentionally masturbates and releases the sperm (or sexual vaginal secretions in the case of women), so of course it comes with a desire and it has the same `illah (cause) in the qiyas process. That is why it breaks the fast.”