The history of contraception goes back nearly to the beginning. The first and perhaps only overt Scriptural reference to preventing pregnancy appears in Genesis chapter 38 with the story of Onan, grandson of Jacob. The text says,
“Judah got a wife for Er, his firstborn, and her name was Tamar. But Er, Judah’s firstborn, was wicked in the Lord’s sight; so the Lord put him to death. Then Judah said to Onan, ‘Sleep with your brother’s wife and fulfill your duty to her as a brother-in-law to raise up offspring for your brother.’ But Onan knew that the child would not be his; so whenever he slept with his brother’s wife, he spilled his semen on the ground to keep from providing offspring for his brother. What he did was wicked in the Lord’s sight; so the Lord put him to death also” (vv. 6–10, NET).
The phrase “whenever he slept with his brother’s wife” tells readers that Onan practiced coitus interruptus as a habit. He did so in order to keep from having to sire, provide for, and give an inheritance to a child who would bear his brother’s name instead of his own. Had Onan impregnated Tamar, the offspring from his first wife would have received less of an inheritance.
Onan had done the math. When Er, Onan’s older brother, died, Onan benefited financially as the double portion allotted to the eldest son passed from Er to himself. This double portion would have increased Onan’s inheritance from one fourth to two-thirds of Judah’s estate. And Onan was greedy to keep all the property in his own name. But he was also willing to exploit Tamar, using her body while guaranteeing she would be destitute in the future. For his wickedness, God dealt with Onan as he had done with Er—he put him to death.
Normally, public humiliation, not death, was the penalty for failing to give children to a brother’s widow (Deut. 25:7–10). The Law says this:
“If a man does not want to marry his brother’s wife, she shall go to the elders at the town gate and say, ‘My husband’s brother refuses to carry on his brother’s name in Israel. He will not fulfill the duty of a brother-in-law to me.’ Then the elders of his town shall summon him and talk to him. If he persists in saying, ‘I do not want to marry her,’ his brother’s widow shall go up to him in the presence of the elders, take off one of his sandals, spit in his face and say, ‘This is what is done to the man who will not build up his brother’s family line.’ That man’s line shall be known in Israel as The Family of the Unsandaled.”
Clearly, failure to fulfill one’s responsibility toward a widowed sister-in-law was shameful. So Onan kept the letter of God’s law by marrying Er’s wife. But in doing so he violated the law’s intent. Of Onan’s refusal to give Tamar a child, Brom—speaking for the Roman Catholic Church—explains why his church says God’s actions against Onan exceeded the law’s usual penalty of causing him shame. Drawing on a long history of both Jewish and Christian commentators, Brom says God punished Onan for spilling his seed because doing so violating natural law (italics added).
Yet the text itself reveals that Onan did something far worse. He obeyed God’s Law in taking Tamar as his wife, but he used her. He helped himself to her body, while refusing to fulfill the intent of the levirate marriage law. Such a refusal meant that not only would Er’s name be forgotten, a terrible fate in the ancient Near East, but Tamar would be destitute, further injured because her marriage to Onan prohibited her from marrying someone else who could guarantee her future. Those who have seen in Onan’s “spilling his seed” a violation of natural law have missed that Onan’s evil was in selfishness, in heartlessness, and in violating a person. Consequently, God—who cares for the widow—raged against the injustice of his actions.
The issue, then, rather than being one of natural law, appears to be in failing to love. The Scriptures tell us that God defends the cause of the widow (Deut. 10:18), and Onan’s story illustrates God’s passion in doing so.
 Brom, Robert H. “Birth Control,” Catholic Answers to Defend the Faith. August 10, 2004. http://www.catholic.com/tracts/birth-control