I am a man, and when I was about fourteen or fifteen years old, I used to masturbate during the day in Ramadan, and I was aware of the ruling, but sometimes I would ejaculate and sometimes I did not. Please note that I had not yet reached puberty at that time, and I do not know the number of days on which I did that. What should I do? What is the ruling?
Praise be to Allah
If the person who is fasting masturbates and emits maniy, he has invalidated his fast, but if he does not emit maniy then his fast is still valid.
Ibn Qudaamah said: If he masturbates with his hand, then he has committed a haraam action, but he has not invalidated his fast, unless he ejaculates. If he ejaculates, then he has invalidated his fast.
End quote. Al-Mughni (4/363)
Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allah have mercy on him) said:
Masturbation during the day of fasting renders the fast invalid if it is done deliberately and the person emits maniy, and he has to make it up if it was an obligatory fast. He must also repent to Allah, may He be glorified and exalted, because masturbation is not permissible either when fasting or otherwise.
End quote from Majmoo‘ Fataawa ash-Shaykh Ibn Baaz (15/267)
The scholars of the Standing Committee for Issuing Fatwas was asked about someone who used to masturbate during the day in Ramadan when she was fourteen or fifteen years old, and she does not know the number of days on which she did that; what should she do?
Firstly, it is haraam to practice the secret habit, and if it is done during the day in Ramadan it is even more emphatically haraam.
Secondly, you have to make up those days on which you broke the fast because of the secret habit, because it invalidates the fast. Try to work out the number of days on which you broke the fast. And Allah is the source of strength. May Allah send blessings and peace upon our Prophet Muhammad and his family and companions. End quote.
Shaykh ‘Abd al-‘Azeez ibn Baaz, Shaykh ‘Abd ar-Razzaaq ‘Afeefi, Shaykh ‘Abdullah ibn Ghadyaan
Fataawa al-Lajnah ad-Daa’imah li’l-Buhooth al-‘Ilmiyyah wa’l-Ifta’ (10/258)
For more information, please see fatwa no. 38074
And Allah knows best.