Wa `alaykum As-Salamu wa Rahmatullahi wa Barakatuh.
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.
Thanks for your question and we implore Allah to guide us all to the best.
Before giving a direct response to your question, we would like first to stress that masturbation is generally considered prohibited because it is not the normal way of fulfilling sexual desire. It is a deviation and that is enough to condemn it even though this act does not fall under the category of absolute prohibition like adultery (zina).
However, the law of necessity, which is one of the principles of the Shari`ah, should also be applied here. For example, if someone is afraid that he would commit a greater sin like adultery or he would be harmed by some psychological disorders, then the ban on masturbation would be relaxed just to remove the hardship, based on the Shari`ah principle stating, “necessity is judged according to the circumstances that warrant it.”
As for your question, we can say that you are required to perform ghusl after masturbation because the Prophet (peace and blessings be upon him) said, “What requires water (ghusl) is if you see water (i.e., semen) coming out of you.” (Muslim)
Allah Almighty knows best.