practicing masturbation is prohibited, because of the general meaning of Allah's saying,
And those who guard their chastity (i.e. private parts, from illegal sexual acts)
Except from their wives or (the slaves) that their right hands possess, - for then, they are free from blame;
You have to abandon this harmful practice and perform sincere Tawbah (repentance to Allah). It may be that Allah will accept your Tawbah and forgive your sin.Secondly,
sodomy is one of the most forbidden depravities and its penalty is death. The Had (prescribed punishment for violating Allah’s Law) must be applied to (Part No. 22; Page No. 12) whoever acknowledges it to the ruler or is proven guilty thereof by four witnesses that he committed this sin. Whoever's fault is concealed by Allah should perform Tawbah, ask Allah's forgiveness and give up this forbidden depravity. It may be that Allah will accept your Tawbah and forgive you for your sin. May Allah grant you success in doing the obligations and avoiding immoralities - what is apparent of them and what is concealed, as He is the Forgiving, the Merciful. It should be noted that killing yourself is prohibited, as Allah (Exalted be He) says,
And do not kill yourselves (nor kill one another). Surely, Allâh is Most Merciful to you.
It was authentically reported that the Prophet (peace be upon him) has greatly warned against Muslims committing suicide. Sincere Tawbah wipes out what came before it.May Allah grant us success. May peace and blessings of Allah be upon our Prophet Muhammad, his family and Companions!