In the name of Allah,
Ejaculation from kissing, touching, masturbating, or erotic gazing invalidates fasting. If any of these happen, the fasting is invalid, but one must make up for it without expiation. Expiation (kaffarah) only applies to having sex. If a person is sleeping and has a wet dream, he can still fast because it was not intentional. To cleanse from janabah, ritual bathing (Ghusl) is necessary[i].
Most Islamic scholars, including the four imams Abu Haneefah, Maalik, al-Shaafa’i, and Ahmad (may Allah have mercy on them), agree that the fast is broken if a man masturbates or comes into contact with his wife to the extent that he ejaculates semen.
Ibn Hazm and Shaykh al-Albaani (may Allah have mercy on them) both believed that ejaculation due to intimacy with one’s wife or merely looking at something does not render the fast invalid.
The evidence of the majority is that according to the Sunnah, a person breaks his fast by deliberately vomiting or cupping. Both make the body weaker.
Food release makes the body hungry and thirsty. Likewise, Semen and blood release weaken and exhaust the body[ii].
They also said that it fulfills a desire, which is forbidden for a fasting person because Allah says in the hadeeth qudsi,
“He gives up his food, drink, and desires for Me.”[iii]
They differ with regard to ejaculation caused by merely looking or prolonged thinking.
The Shafis say that unintentional emission with a barrier between skins doesn’t break the fast. Viewing or thinking about anything that induces ejaculation (without touching the skin) does not break the fast, even if done intentionally (and even if the thing being watched or thought about is haram – which itself is a major sin).
Yet a very strong and serious belief in the Shafi school is that if a person knows they will ejaculate and does, the fast is broken and they must make up the day[iv]. Click here for the details on the difference of opinion on this issue.
If a person begins masturbating but stops before ejaculating
If a person begins masturbating but stops before ejaculating he must repent but is not required to make up. People who are fasting must avoid temptations and bad ideas. Prostatic fluid (madhiy) doesn’t break his fast[v].
To know What are the things that invalidate fasting, click here.
May Allah’s peace and blessings be on the last and final prophet
Sources:
[i] A summary of Islamic Jurisprudence by Dr. Salih Al-Fawazan, Vol 2- page 388
[iii] Sahih al-Bukhari 7492
[iv] The fiqh of fasting Ramadan according to the school of Imam shafi‘I, SeekersGuidance, Page 60
[v] Rulings pertaining to Ramadan, A Collection of Works by Sheikh Muhammad Salih Al-Munajjid, Islamfuture, page 52