Ruling on Male Discharge during Fasting
Question

 
I woke up when I was fasting during the day in Ramadan, and I found that I was emitting maniy (semen), but I do not know whether it was accidental (i.e., from a wet dream) or deliberate (i.e., from masturbation), because when I woke up I found my hand touching my penis.
What should I do?
Praise be to Allah.Firstly: 
How does Islam see wet dreams?
Wet dreams are a means of releasing sexual energy in both sexes, and the individual plays no part in that; rather they happen to him when he is asleep, and are part of the nature of the human being. The individual will not be brought to account for that, because the Pen is lifted from one who is asleep (and his deeds are not recorded). 
Does a wet dream break your fast?
If the emission of maniy from you during the day in Ramadan happened because of a wet dream , then this does not invalidate the fast. This is because this is something that is beyond a person’s control and he cannot prevent it. Allah, may He be glorified and exalted, said: “On no soul does Allah place a burden greater than it can bear” [al-Baqarah 2:286]. 
Ibn Qudamah said:
“If a person has a wet dream, it does not invalidate his fast, because it was involuntary on his part. It is similar to the case if something enters his throat whilst he is sleeping.” (Al-Mughni by Ibn Qudamah (3/128). 
The Standing Committee was asked about a man who had a wet dream during the day in Ramadan: what is the ruling? They replied: 
“Whoever has a wet dream when he is fasting or is in ihram for Hajj or ‘Umrah, there is no sin on him, he does not have to offer expiation, and it does not affect his fast, but he has to do ghusl from janabah if maniy was emitted.” (Fatawa al-Lajnah ad-Daimah, 10/274) 
Does masturbation break your fast?
If the emission of maniy during the day in Ramadan occurred as a result of masturbation when the person was awake and aware of what was happening, then his fast is invalidated and he has to repent to Allah , may He be glorified, for having masturbated because masturbation is a forbidden action . 
He also has to repent from masturbating during the day in Ramadan, because by doing this deed he has violated the sanctity of the fast. Then after repenting, he has to make up that day on which he invalidated his fast. 
Shaykh Ibn Baz said: 
“Masturbation on the day of fasting invalidates the fast if it was done deliberately and he emitted semen. He also has to make up that day if it was an obligatory fast, and he has to repent to Allah, may He be glorified and exalted, because masturbation is not permitted at the time of fasting or otherwise. It is what people call ‘the secret habit.’” (Fatawa ash-Shaykh Ibn Baz, 267/15)
Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) said: 
“If the fasting person masturbates and ejaculates, he has broken his fast and he has to make up for the day on which he masturbated. But he does not have to offer expiation, because expiation is only required in the case of intercourse. He also has to repent from what he has done.” (Fatawa Arkan al-Islam, p. 478) 
As you are confused and you do not know whether this maniy was emitted because of a wet dream or masturbation, it is to be taken as the result of a wet dream, because the basic principle with regard to the sleeper is that he is innocent and is not accountable at that time. 
So we should act on the basis of this principle and not do otherwise except on the basis of certainty. This ruling does not change even if the emission of maniy came about as a result of you playing with your private parts, so long as you were asleep, because an action done by one who is sleeping is as if it did not happen, because he is not accountable at that time. 
Shams ad-Din al-Asfahani said: “There is no differentiation between one who is dead, one who is sleeping, and one who is out of his mind with regard to the ruling being waived for them, because we know on the basis of reason that one of the conditions of accountability is that one should be aware of what he is doing.” 
And Allah knows best.