Masturbation is a major sin. One should repent from this act, pledge firmly not do it again in future and seek forgiveness from Allah Almighty. As far as the punishment is concerned, if his act is known, then it is the government which can give punishment whatever it sees suitable.
However, one should fix any punishment for himself, for example he should have an intention to perform 50 rakah nafl salah if committed this sinful act, or to give 100 rupees in sadqah. So, one can fix punishment for himself and he will have to fulfil it if commits the sin.
Allah (Subhana Wa Ta’ala) knows Best
Darul Uloom Deoband