The immediate context suggests that Onan's wrongdoing involved more than the physical act described in the passage. He knowingly accepted the benefits of a relationship with Tamar while deliberately refusing the family obligation associated with it.
In the ancient world, preserving a deceased brother's family line and inheritance was considered an important responsibility. The later Law of Moses established provisions for such marriages, although Onan lived long before those laws were formally given.
Some Christian traditions have interpreted the passage as having broader implications for sexual morality and the deliberate prevention of conception. Other Christian commentators emphasize that the central offense was Onan's selfish refusal to provide an heir for his brother and his exploitation of Tamar.
The narrative particularly stresses Onan's knowledge and intention. He deliberately frustrated the responsibility he had been given while continuing to take advantage of his position.