This passage is frequently misinterpreted as a blanket condemnation of contraception or masturbation due to Onan's later refusal to impregnate Tamar and his spilling of seed, but the core issue was his selfish violation of the levirate duty—not the act itself—aimed at usurping his brother's inheritance rather than fulfilling familial obligations, with Onan's punishment stemming from disobedience and wickedness, not isolated sexual behavior.
Genesis 38:8
King James Version (1769)
8 And Judah said unto Onan, Go in unto thy brother’s wife, and marry her, and raise up seed to thy brother.
Genesis 38:8 reflects the ancient Israelite custom of levirate marriage, where Judah instructs Onan to marry his deceased brother Er's widow Tamar and produce offspring on his behalf, ensuring the continuation of the family line, inheritance rights, and the deceased brother's name within the community, a practice later formalized in Deuteronomy 25:5-10 to protect widows and preserve tribal lineage.