Here is the passage we are examining from Genesis 38:9-10:
38:9 וַיֵּדַע אוֹנָן כִּי לֹּא לוֹ יִהְיֶה הַזָּרַע וְהָיָה אִם־בָּא אֶל־אֵשֶׁת אָחִיו וְשִׁחֵת אַרְצָה — But since Onan knew that the offspring would not be his, he spilled his semen on the ground whenever he went in to his brother’s wife, — The wording of the text “ba” suggests Onan’s behavior was not a one time action; he seems to have habitually climaxed in this manner. The NRSV’s translation, “whenever he went in . . .” is preferable to other Bible translations that read “when he went in.”
וַיֵּרַע בְּעֵינֵי יְהוָה אֲשֶׁר עָשָׂה וַיָּמֶת גַּם־אֹתוֹ — What he did was displeasing in the sight of the LORD, and he put him to death also — We really don’t know why Onan died. The ancients viewed the sudden death of a young person as an act of God, Who serves as the Ultimate Cause for everything that unfolds within the natural world. Moderns, in contrast, tend to attribute events that occur in the phenomenal world to more direct and scientific causes. To understand the Bible, it is helpful to see it through the eyes of the people who wrote it.
To the rabbinic imagination, God punishes Onan because he preferred to spill his seed rather than give it to Tamar, his levirate wife.
However, a closer examination of the text reveals a different approach that contradicts conventional rabbinic thinking found in the rabbinic writings of the Talmud, Midrash and especially the Zohar. It is apparent from the narrative Onan’s sin was not primarily sexual in nature. Rather, it was his refusal to fulfill the obligation of levirate marriage (Deut. 25.5–10). On a historical note, several Jewish and Christian exegetes interpret the story of Onan as a condemnation any sexual act other than for the purpose of procreation, as one notable 20th century Halachic scholar, R. Aharon Walkin, explains:
“As for the doubt about whether it is permitted to follow this procedure because of the prohibition against ‘bringing forth seed in vain,’ if we follow the earlier sages, it seems that the Talmud and subsequent halachic scholars agree that doctors are to be trusted even in cases where certain prohibitions (of the religious law) are involved. If, then, the doctors’ words are correct, that by this procedure it will be easier for her to become pregnant, since this is the physical nature of this woman, then this procedure (of taking the seed) is not ‘in vain’ at all. On the contrary, it is for the purpose of achieving pregnancy more easily. The rabbis forbade bringing forth seed in order to destroy it, but here there is no destruction; it is placed into the womb of the wife in order that she shall be impregnated. Then, clearly, there is nothing wrong with this procedure. ”
Contextually speaking, let us also observe that Onan’s behavior made him guilty of the following offenses:
* Fraud — by failing to fulfill the obligation of the levirate marriage and in the process dishonored the memory of his dead brother.
* Greed — by taking advantage of Tamar’s status and used her like a mere concubine.
* Exploitation — Although Onan refuses the responsibilities that came with the levirate marriage, he insists on taking advantage of its privileges. The sexual exploitation of another is soundly condemned in this passage.
* Theft — Strange as it may sound, Onan was determined Er would never have an heir (pardon me, I could never resist the occasion to make a pun!), and this way he would inherit the double-portion inheritance of his dead brother for himself and in doing so he acted unfairly to both his deceased brother and Tamar.
 In the Zohar, the gravity of “destroying one’s seed” through masturbation was considered to be the most severe of sins. “Now of all the sins which defile a man, that which defiles him the most, both in this world and in the world to come, is the sin of spilling one’s seed (semen). A man guilty of this sin will not enter within the Heavenly Curtain, and will not behold the presence of the Ancient of Days. So we learn from the recurrence of the word “evil” here and in the verse: “For You are not a God who delights in wickedness; evil will not sojourn with You” (Psa. v, 5).It was on account of this sin, too, that the prophet said to the people, “your hands are full of blood” (Isa. I, 15). – Zohar 186b Fortunately, not all the Halachic literature bears such an attitude towards this “ most defiling sin.” David Feldman writes in his article on Onan in the EJ “R. Jacob Emden (d. 1776), addressed himself to the difference between the Talmudic and Zoharic attitudes toward onanism in the sense of masturbation, which has consequences for the question of birth control. He prefers the attitude of the Talmud, and calls that of the Zohar “exaggeration” (Mitpahat Sefarim (Altona, 1768), 1:20). More important, he emphasizes a doctrine, articulated by earlier legal authorities, that the prohibition against onanism in method is not applicable to marital contraception; that when contraception is necessary and abstinence would be the alternative, then possible onanism in the use of a contraceptive device is neutralized by the positive mitzvah of marital sex. “ For a more comprehensive study of this issue see D. Feldman’s Birth Control in Jewish Law (New York: New York University, 1968), 148-1
 Even as late as the Victorian-era doctors generally agreed that the act of “self-pollution” could lead to a variety of ailments, as one doctor wrote back in 1908: “The physical symptoms are weakness, pallor, and backache and general debility. The effects on the brain and nervous system are more serious. They may dull the intellect, weaken the memory and the affections, produce listlessness, apathy, moroseness, and morbid irritability, in short a general perversion of character” cited from Elwood Worcester, D.D., Ph.D., Samuel MacComb, M.A., D.D. and Isador H. Coriat, M.D., “Religion and Medicine: The Moral Control of Nervous Disorders,” cited from Jim Hill and Rand Cheadle’s “The Bible Tells Me So – Uses and Abuses of Holy Scripture” (New York: Anchor Books, 1996), p. 47.
 Aharon Walkin’s Responsa Zekan Aharon, Vol. II, Eben HaEzer, Responsa 97.