disliked but not forbidden. Most of them do not permit it, whether for fear of hardship or for any other reason. It is reported from a group of the Companions and their successors that they permitted it in cases of necessity: for example, when someone fears committing unlawful sexual intercourse and can only keep himself from it in this way, or fears becoming ill if he does not do it. This is the view of Ahmad and others. Without necessity, however, I know of no one who permitted it. And Allah knows best.
He was also asked—may Allah Most High have mercy on him:
About a man who becomes sexually aroused and masturbates with his hand, and sometimes presses his hips against his penis. He knows that fasting would relieve this, but finds it difficult.
He replied:
As for semen discharged involuntarily, he incurs no sin on that account. He must, however, perform a full ritual bath if he ejaculates semen.
As for deliberately causing ejaculation by masturbating with his hand, this is forbidden according to most scholars. It is one of the two positions reported from Ahmad—indeed, the stronger of the two. According to another report, it is disliked.
If, however, he is compelled by necessity—for example, he fears committing unlawful sexual intercourse if he does not masturbate, or fears illness—then the scholars have two well-known views concerning this. Groups of earlier and later scholars permitted it in such circumstances, while others prohibited it. And Allah knows best.