Allah (Exalted is He) says: “And those who guard their private parts from their wives and those (slave-girls) which their right-hands own - so there is no blame upon them. Then whoever seeks beyond that (which is lawful), they are the transgressors”.
Masturbation is also considered as “seeking beyond” with reference to the Quranic verse above.
Suhail son of Sai’d (may Allah be pleased with them) narrates that the Holy Prophet (Allah’s’ Grace & Peace be upon him) said: Whoever gives me the assurance (not to unlawfully use) what is between their jaws and their legs (i.e. the tongue and the private parts), I give them the assurance of the Heaven. (Bukhari)
Abu Hurrairah (may Allah be pleased with him) narrates that the Prophet of Allah (Allah’s Grace & Peace be upon him) said: Whoever Allah protects, from the evil (sh’r) of what is between their jaws and between their legs, will enter Paradise. [Tirimzi]
Imam Shamsuddin Zahabbi
(may Allah be pleased with him) narrates a Prophetic narration
that, “Seven people are such that Allah has cursed them
and He will not even cast a look of mercy upon them on the Day
of Judgment. Allah will tell them to enter Hell with the people
who are going to Hell, except those who repent.
1. One who performs the act of sodomy.
2. One upon whom the act of sodomy is performed.
3. One who does bad deeds with animals.
4. One who marries his mother or sister.
5. One who masturbates.” (The words of the hadith says these seven people but lists five - Kitab-ul-Kaba’ir p.48)
Allama Mahmood Alussi (may Allah be pleased with him) narrates in Ruh-ul-Ma’ni: “Atta (may Allah be pleased with him) says that I have heard that on the Day of Judgment one group will be brought in such a way that their hands will be pregnant. I think they are the masturbators.” Allama Alussi further says: Saéed bin Jubayr (may Allah be pleased with him) narrates that the Prophet (Allah’s Grace & Peace be upon him) said: “Allah Exalted will inflict punishment on a group of people because they misused their private parts.” (Ruh-ul-Ma'ni p. 291)
Anas (may Allah be pleased with him) narrates that the Prophet of Allah (may Allah be pleased with him) said: “The person who performs marriage [nikah] with his hands (i.e. masturbates) is cursed.” (Fatawa Razaviyya, Vol. 10, p.80)
Abdullah bin Masood (may Allah be pleased with him) reports that the Holy Prophet (Allah’s Grace & Peace be upon him) said: “O group of youth! Whoever from among you can marry should do so because it keeps the gaze low and it protects the private parts. And he who cannot marry should fast because fasting breaks lust.” (Muslim – Book of Marriage)
Mufti Waqar-ud-din Al-Qadri (Hanfi) writes in “Waqar-ul-Fatawa” (Vol. 1, P. 269): “If a person is overpowered by sexual desire such that there is fear of him becoming involved in adultery or he is not capable of marrying or his wife is so far that he can't go there. Then it is hoped there is no punishment for the one doing this [masturbation]. It is written in “Durr-e-Mukhtar” (Vol. 2, Pp 109) (by Sheikh Alla’ud Din Muhammed son of Ali Haskiffi, died 1088H): ‘If there is fear of committing adultery then it is hoped that there is no punishment on the one doing this (masturbation)’. Allama (Syed Mohammed Amin Ash-Shaheerba Bin Abideen) Shammi, (may Allah’s mercy be upon him, died 1253H) has also argued on this quite a lot and decided that if he does this with the intention of saving himself from committing sin it will not be a sin and if he does it with the intention of enjoyment he will be a sinner.”
The Holy Prophet (Allah’s Grace & Peace be upon him) said, "No doubt the virtues wipe away the sins". Therefore a masturbator must repent sincerely with an intention that he will never commit it again and do good deeds. According to a Prophetic narration, "The one who repents is like the who does not have any sin."