Great question as many of us have fallen to the victim of pornography and therein leads to masturbation.
And do not approach unlawful sexual intercourse. Indeed, it is ever an immorality and is evil as a way. [17:32]
In this particular ayah, Allah said, not to approach but he didn't say not to do unlawful sexual intercourse. Because the thing is Allah made us with some vulnerabilities and this is one of them so Allah knows even if you approach this act you will commit fornication. That's why Allah said Do Not Approach.
Now, some will argue about the definition of Sextual Intercourse.Well, let's get to that, according to google it has two definitions
- Special
- Typical

Take what suits you best but I'll go with the typical one cause that's what all matters in the end Orgasm. So, I think it's clear that Masturbation too is forbidden and sinful act.
Some people will also imply that in Islam Haram/Forbidden things are clear but there is not one mention of Masturbation being Haram/Forbidden in the Hadith of Prophet Muhammad (PBUH). So, how can you say it's haram? unless there is a clear mention of it.Well, I won't argue about that, cause enemies of Islam always trying to distract us from the transparent to leave us astray. Take your time and do your research if you're not satisfied with my answer.
For more go to this website.
Allah knows best.