Once Imam Ali (as) caught someone doing this. He hit him on his hand and then went to get him married so he didn’t commit this sin again.
Also, If someone knew he could masturbate than he would just do that and may prolong getting married.
Masturbation also can cause health problems, such as blindness.
These are just a few reasons. Allah knows best.