Rabbi Johanan stated: Whosoever emits semen in vain deserves death, for it is said in Scripture, "And the thing which he [Onan] did [spilling his semen on the ground] was evil in the sight of the Lord, and He slew him also." [Gen. 38:9]
Rabbi Isaac and Rabbi Ammi said. He is as though he shed blood, for it is said in Scripture, "Ye that inflame yourselves among the terebinths, under every leafy tree, that slay the children in the valleys under the clefts of the rocks;" read not 'that slay' but 'that press out'.
Rab stated: 'A man who wilfully causes erection should be placed under the ban'. But why did he not say, 'This is forbidden'? Because the man merely incites his evil inclination against himself. R. Ammi, however, stated: He is called a renegade, because such is the art of the evil inclination: To-day it incites man to do one wrong thing, and to-morrow it incites him to worship idols and he proceeds to worship them.
There are others who read: R. Ammi stated, He who excites himself by lustful thoughts will not be allowed to enter the division of the Holy One, blessed be He. For here it is written, Was evil in the sight of the Lord, and elsewhere it is written, For Thou art not a God that hath pleasure in wickedness; evil shall not sojourn with Thee.
R. Eleazar stated: Who are referred to in the Scriptural text, Your hands are full of blood? Those that commit masturbation with their hands.
It was taught at the school of R. Ishmael, Thou shalt not commit adultery implies, Thou shalt not practise masturbation either with hand or with foot.
Quoted from The Babylonian Talmud: Tractate Niddah Folio 13a, Chapter II