Answer
In the Name of Allah, Most Gracious, Most Merciful.
All praise and thanks are due to Allah, and peace and blessings be upon His Messenger.
In this fatwa:
You need to perform ghusl only if you ejaculated because of masturbation. We advise any Muslim involved in masturbation to resort to Allah seeking His help.
Responding to your question, Sheikh Ahmad Kutty, a senior lecturer and an Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states:
You need to perform ghusl only if you ejaculated because of masturbation.
Since it is a grave sin, I advise you to break this habit. However, you can break it if you are willing to motivate yourself and take the necessary steps.
We advise any Muslim involved in this sinful practice of masturbation to resort to Allah seeking His help, and be assured that by returning to Allah with sincere repentance, He will never forsake him/her and will make it easy for him/her to give up such sinful act.
Almighty Allah knows best.