Basically, Onan refuses to follow the law of the Old Covenant by refusing to birth a child with his dead brother's wife and the Good Lord decides to kill him.
The wrath of God returns
The Bible is one of the greatest books to read simply because there are so many interpretations to what is being said.
The danger comes when a person takes the passage for its face value.
The assumed meaning:
In this passage, God killed Onan because he refused to fulfill his familial responsibility where a dead man's closest unmarried male relation married the widow to produce an heir for the dead man. In this case, the dead man was Onan’s older brother, Er.
On face value:
Well, to be fair to Onan, Judah’s plan sounds strange and, to make matters worse, it really doesn’t sound like Judah gave Onan much of a choice. The tone in the passage suggests that Judah forced Onan into this:
Genesis 38; 8-10 (New International Version)
8. Then Judah said to Onan, "Lie with your brother's wife and fulfill your duty to her as a brother-in-law to produce offspring for your brother."
9. But Onan knew that the offspring would not be his; so whenever he lay with his brother's wife, he spilled his semen on the ground to keep from producing offspring for his brother.
10. What he did was wicked in the Lord’s sight; so he put him to death also.
I mean, I know biblical era laws were a bit strange but what is this “fulfill your duty to her as a brother-in-law to produce offspring for your brother”?
I’m pretty sure that that if I had an my older brother and he passed on, the LAST thing he and his wife would want me to do is to fulfill my duty to her as a brother-in-law.
I can also somewhat sympathize with Onan as his child was going to be raised as Er’s heir, something that most men wouldn’t stand for in this day and age.
But what he did was also inexcusable.
Why would you lay with Tamar if you weren’t intending on giving her a child? That’s real shady. It’s as if he was using the poor lady just to get his rocks off and that is something that God doesn't tolerate.
Dude was asking for God’s divine judgment and the Good Lord obliged, proving once again that there are certain forces you can trifle with.
God is not one of them.