Is masturbation haram?
Masturbation refers to self-stimulation of the genitals to the point of orgasm. There is no one definite legal ruling on masturbation as it was not mentioned explicitly in the Quran as well as by the Prophet s.a.w. Despite the variety of opinions ranging from the prohibited to permissible, most scholars are of the opinion that it is legally neutral or mubah when it becomes necessary to release the sexual tension that may have built up in a Muslim person; especially, if the alternative would lead to non-marital sexual relations or zina. This is based on the jurisprudential principle of choosing the lesser of two evils.
Although it is legally neutral, it should be regarded as a last resort and not become a Muslim’s habitual source of sexual pleasure. Islam encourages a Muslim with healthy sexual drives to channel it towards sexual enjoyment with a legally married spouse. Failing which, he is enjoined by the Prophet ﷺ to control his desires through fasting.
“’He who can afford to marry should marry, because it will help him refrain from looking at other women, and save his private parts from committing illegal sexual relation; and he who cannot afford to marry is advised to fast, as fasting will diminish his sexual power.” (Hadith reported by Bukhari)
This is what we understand from the thorough discussion by the jurist Sayyid Sabiq in his book, Fikih Sunnah, translated into Malay by Mahyuddin Syaf, Al-Azhar, 1987; pages 137 – 138.