The Onan Incident (Gen. 38:8-10, Dt. 25:5-10)
Some say "Onan was killed by God because he didn't show love for his brother by having a child. He should have had at least one child before practising birth control, and then God wouldn't have been angry." Deuteronomy eliminates this reason as a possibility, because it says that regardless of a man's motives for refusing to raise up seed for a dead brother, the man is not to be put to death. He is to be humiliated only ... Onan was put to death for what he did, while the man in Dt. 25 is not. As we compare the two Bible texts, we need to ask, "What did Onan do that the man of Dt. 25 didn't do?" ... the difference is that while Onan wasted his seed, the other man didn't!
That misses a key point. This wasn't just any coupling. From this union, came the tribe of Judah, from whom the Jews are descended.
In other words, Onan's act almost prevented the line from which the Messiah will come (or has come, if you are Christian). That was the crime worthy of the severe penalty.
The passage in Deuteronomy recites a law handed down several centuries after the events described in Genesis 38:8-10. It is thus clearly inapplicable.
The difference is Onan went into his brother's wife, and then shamed her. The hypothetical in Deut. simply refuses to perform the rite at all.