Praise be to Allah.
Masturbation is haraam because of evidence that we have quoted previously in the answer to question no. 329
As it is haraam, then there is no way that it could be a remedy, because Allah has not put healing in that which He has forbidden to His slaves.
Ibn Mas‘ood (may Allah be pleased with him) said: Allah has not put your healing in that which He has forbidden to you. Narrated by al-Bukhaari in a mu‘allaq report in Kitaab al-Ashribah, Baab Sharaab al-Halwa wa’l-‘Asl.
A person may imagine that something is a remedy when in fact it is a disease, such as the one who imagines that there is healing in khamr (wine, alcohol), as it says in the hadeeth that was narrated by Muslim (3670) via Suwayd al-Ja‘fi who said that he asked the Prophet (blessings and peace of Allah be upon him) about khamr and he forbade him or discouraged him from making it. He said: I only make it as a remedy, and the Prophet (blessings and peace of Allah be upon him) said: “It is not a remedy; rather it is a disease.”
Masturbation is also like that; you may think that it is a remedy when in fact it is a disease. The one who suffers from it can hardly give it up and has no limit at which he can stop. With regard to fasting, it is a beneficial prophetic remedy, but it needs to be done regularly and on an ongoing basis, whilst also following other preventative measures such as lowering the gaze, avoiding idleness, keeping busy with acts of worship and obedience, and choosing righteous friends.
Some fuqaha’ allowed masturbation in cases where the individual fears for his religious commitment or physical well-being, under the heading of committing the lesser of two evils.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) was asked about a man who was faced with provocation of desire, so he masturbated although he knew that the problem could be dealt with by fasting, but it was too difficult for him.
With regard to that (semen) that is emitted involuntarily, there is no sin on him for that, but he has to do ghusl if the water came out gushing. But if it was emitted voluntarily, in that he masturbated, this is haraam according to most of the scholars. It is also one of the two views narrated from Ahmad; in fact it is the more correct view; according to another view it is makrooh (disliked). But if he is compelled to do that, such as if he feared that he might fall into zina if he did not masturbate, or he feared that he might become ill, then in this case there are two well-known scholarly views. Some of the earlier and later scholars granted a concession in such cases, and others forbade it. And Allah knows best.
End quote from al-Fataawa al-Kubra, 3/439. See also Mataalib Ooli an-Nuha, 6/225; Kashshaaf al-Qinaa‘, 6/125
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: He said: “The one who masturbates unnecessarily should be given a disciplinary punishment.” The phrase “unnecessarily” means if there was no need to do that. Needs are of two types: religious or spiritual needs and physical needs.
With regard to religious or spiritual needs, that refers to when the individual fears that he may fall into zina, if he is in a country where it is easy to commit zina. If he experiences intense desire, he will have two options: either he can extinguish it by doing this action or he can go to any place where there are prostitutes and commit zina. In that case we say to him that this is a legitimate need, because the established principle in Islam says that it is essential to ward off the greater of two evils by means of the lesser, and this is what is in accordance with reason. If this person has no option but to fulfil his desire in one of these two ways, then in that case we say that it is permissible for him to do this action because it is a case of necessity.
With regard to physical needs, that refers to when the individual fears that some harm may befall his body if he does not discharge this fluid from his body, because some people may experience strong desire, and if this accumulating fluid is not discharged it will result in psychological problems, so he will not like to mix with people or sit with them.
So if he fears some kind of physical harm, then it is permissible for him to do this action because it is a physical need. But if there is no need and he does this action, then he should be given a disciplinary punishment that will serve as a deterrent.
End quote from ash-Sharh al-Mumti‘, 14/318
You should avoid anything that may provoke desire of looking, listening, reading and so on, and you should avoid keeping company with those whose company may lead to that, so as to protect your religious commitment and your physical well-being. Please see the answer to question no. 20161 for some advice on resisting the danger of sexual temptation.
If a man offers to give you his daughter in marriage and to spend on you both, and this man is religiously committed and righteous, and there is no fear that he will break his promise or remind you of his kindness later on, then there is nothing wrong with accepting that from him; perhaps this is provision that Allah has granted to you and a way out by which you can be safe from falling into haraam.
As for marrying with the intention of divorcing, that is haraam, because it involves deceiving and cheating the wife. This has been discussed previously in the answer to question no. 111841
We ask Allah to make things easy for you, purify your heart and protect your chastity.
And Allah knows best.