Masturbation
In relation to masturbation, the following has been mentioned in the Hanafi school:
“Masturbation is prohibited i.e., with the hand if it is to bring on sexual desire, as for when he is overcome with sexual desire and he has no wife and does it to settle the sexual desire then the hope is that there is no sin upon him as Abu Al-Layth said, and he must do it if he fears illicit sexual intercourse.”[1]
Also, the following has been mentioned in the Hanbali school.
“Whoever masturbates without a need whether a man or a woman; it is prohibited and they are punished for it because it is disobedience. If they do it out of fear of fornication or homosexual acts then there is no blame upon them just as if they did it out of fear for their body, even more so. Therefore, masturbation of a person with their hand is not permitted unless they are unable to marry.”[2]
Answered by Shaykh Bilal Brown
[1] (Radd al-Muhtar, Chapter of Sexual Intercourse That Necessitates a Legal Punishment).
[2] (Sharh Muntaha Al-Iradat, Book of Legal Punishments [Chapter of Discretionary Punishments]).