"In the case of Onan, you are right that the common Catholic reliance on this passage as a proof text against contraception or masturbation is a weak one and wrong-headed. The point of the story is that Onan dishonored the natural law by failing to provide an heir for his brother and his widow (recall that children were the sole “social safety net” that widows had, so the main sin in view in the text of Genesis is Onan’s betrayal of his family by refusing to give his brother’s wife children after his brother had died)." (Mark Shea)It is easy here to see that Mr. Shea falls into the error of "modern" Biblical scholarship. There is no question as to what the heinous act which Onan was killed for in Genesis 38. The "detestable" act was the intentional act of spilling his seed outside of intercourse. Does Mr. Shea ever wonder why the "Sin of Onan" has always throughout history been identified with the contraceptive act? Furthermore, just so that Mr. Shea will not come along and call me a flat-footed fundamentalist, like he often does with people who disagree with him, let's see where else this interpretation of the "Sin of Onan" has also been identified with the contraceptive act. If you guessed that it is the Catholic Magisterium, you would be correct. For Mr. Shea however, I am sure that Pope Pius XI and the great Saint Augustine would make his flat-footed fundamentalist list today.
"Since, therefore, the conjugal act is destined primarily by nature for the begetting of children, those who in exercising it deliberately frustrate its natural power and purpose sin against nature and commit a deed which is shameful and intrinsically vicious. Small wonder, therefore, if Holy Writ bears witness that the Divine Majesty regards with greatest detestation this horrible crime and at times has punished it with death. As St. Augustine notes, "Intercourse even with one's legitimate wife is unlawful and wicked where the conception of the offspring is prevented. Onan, the son of Juda, did this and the Lord killed him for it."(Pope Pius XI- Casti Connubii- para 54-55)
So here we have the Church in a formal document, concerning marriage and procreation, which clearly references Genesis 38 and the "Sin of Onan" with the contraceptive act. If you want to know more about this you can reference my other article to which I linked above, or check out this article by John F. Kippley which was published in 'Homiletic & Pastoral Review', in May 2007. His conclusion likewise states, "In summary, the Onan account is an important part of the Christian Tradition against contraceptive behaviors. Claims that Onan was slain by God simply for his violation of the law of the Levirate are not sustained by the text itself and are further disproved by the text of Deuteronomy 25: 5-10. The anti-contraception interpretation of the text was reflected by St. Augustine and confirmed by Pius XI in Casti Connubii."