9. The Bible exhibits the wrath of God upon those who defy His will (Gen. 38:8-10; Exod. 21:22; Rom. 1:18).
8 And Judah said to Onan, “Go in to your brother’s wife and marry her, and raise up an heir to your brother.” 9 But Onan knew that the heir would not be his; and it came to pass, when he went in to his brother’s wife, that he emitted on the ground, lest he should give an heir to his brother. 10 And the thing which he did displeased the LORD; therefore He killed him also.
22 “If men fight, and hurt a woman with child, so that she gives birth prematurely, yet no harm follows, he shall surely be punished accordingly as the woman’s husband imposes on him; and he shall pay as the judges determine.
18 For the wrath of God is revealed from heaven against all ungodliness and unrighteousness of men, who suppress the truth in unrighteousness,
The church throughout all ages has universally condemned the sin of Onan as the sin of family planning: St. Ambrose, Bishop of Milan (c. 339-397), Hexameron, 5.18.58; Athenagoras of Athens, Letter to Marcus Aurelius in 177, Legatio pro Christianis ("Supplication for the Christians"), page 35; St. Augustine, Bishop of Hippo (354-430), De Nuptius et Concupiscus ("On Marriage and Concupiscence"), 1.17; Barnabas (c. 70-138), Epistle, Volume II, page 19; St. Basil the Great, First Canonical Letter, Canon 2 (A.D. 374); Caesarius, Bishop of Arles (470-543), Sermons, 1.12; Clement of Alexandria, "The Father of Theologians" (c. 150-220), Christ the Educator, Volume II, page 10. Also see Octavius, c.30, nn. 2-3; Ephraem the Syrian, De Timore Dei, page 10; St. Jerome, Letter to Eustochium, 22.13 (A.D. 396); St. John Chrysostom, Homilies on Romans 24 (A.D. 391); Letter of Barnabas 19 (A.D. 74); Hippolytus, Refutation of All Heresies (A.D. 228); Lactantius, Divine Institutes 6:20 (A.D. 307); Minucius Felix, Octavius, 30 (A.D. 226); Origen of Alexandria (185-254), Against Heresies, page 9; Tertullian, Apology, 9:8 (A.D. 197), and The Soul, 25,27 (A.D. 210).
Augustine had this to say about Onan's sin:
And why has Paul said: 'If he cannot control himself, let him marry?' Surely, to prevent incontinence from constraining him to adultery. If, then, he practices continence, neither let him marry nor beget children. However, if he does not control himself, let him enter into lawful wedlock, so that he may not beget children in disgrace or avoid having offspring by a more degraded form of intercourse. There are some lawfully wedded couples who resort to this last, for intercourse, even with one's lawfully wedded spouse, can take place in an unlawful and shameful manner, whenever the conception of offspring is avoided. Onan, the son of Juda, did this very thing, and the Lord slew him on that account. Therefore, the procreation of children is itself the primary, natural, legitimate purpose of marriage. Whence it follows that those who marry because of their inability to remain continent ought not to so temper their vice that they preclude the good of marriage, which is the procreation of children.
Onan must have been a malicious and incorrigible scoundrel. This is a most disgraceful sin. It is far more atrocious than incest and adultery. We call it unchastity, yes, a Sodomitic sin. For Onan goes in to her; that is, he lies with her and copulates, and when it comes to the point of insemination, spills the semen, lest the woman conceive. Surely at such a time the order of nature established by God in procreation should be followed. Accordingly, it was a most disgraceful crime to produce semen and excite the woman, and to frustrate her at that very moment. He was inflamed with the basest spite and hatred. Therefore he did not allow himself to be compelled to bear that intolerable slavery. Consequently, he deserved to be killed by God. He committed an evil deed. Therefore God punished him. [Luther's Works, vol. 7 : Lectures on Genesis: Chapters 38-44 (Ge 38:9-10)]
[What he did] which was an abhorrent thing and worse than adultery. For such an evil deed strives against nature, and those who do it will not possess the Kingdom of God, 1 Cor. 6:9-10. And the holier marriage is, the less will those remain unpunished who live in it in a wicked and unfitting way so that, in addition to it, they practice private acts of villainy.
It is simply a denial of orthodox theology for one to deny that Onan was killed for family planning. Our postmodern world would like this to be interpreted otherwise, but it simply cannot be.