Joliette - you are thinking of the account of Onan. It is nothing to do with masturbation.
Genesis 38 v 6 - 11.
*** w83 6/1 p. 26 Maintaining God’s View of Sex ***
There are those that have said that the Bible describes masturbation in Genesis chapter 38, and that Onan was put to death for the offense. But this is not true. The Bible says that when Onan “did have relations with his brother’s wife he wasted his semen on the earth.” (Genesis 38:9) So apparently Onan interrupted sexual relations with Tamar, spilling his semen on the ground rather than giving it to Tamar. He did this because he did not want to raise up children in the name of his dead brother. And it was for this failure to perform “brother-in-law marriage” that Onan was put to death.
Back in the time of Genesis there was a tradition that if a younger woman became a widow without children then the brother-in-law would take her as a wife and try to impregnate her. (Crazy I know)
But good old Onan didn't want to look after kids that weren't his and so "pulled out" before ejaculating.
So in his all encompassing wisdom the great Jehovah not only killed the woman's first husband, he killed his brother (her next husband) as well.
No wanking involved - at least not in the scripture and even WT acknowledge this.
Old Testament stuff which doesn't have the power of law even if you are a Christian believer anyway.