When a man dies without children, his brother is expected to marry the widow to establish a family line for the deceased. Onan, however, actively resisted this duty, driven by a complex mix of psychological, financial, and selfish motives. He knew that any child born from this union would not be considered his own. This awareness came either from his father's explicit instructions [רד״ק] or from his own logical deduction [רא״ש, חזקוני]. Another perspective suggests Onan possessed a deeper intuition that the future royal lineage was destined to emerge from his brother Er. By preventing his brother from having an heir, Onan hoped to claim this glorious dynasty for himself [אלשיך].
The understanding that the child would not be his did not mean the infant would literally bear the deceased brother's name. Rather, the child would be legally recognized as the dead brother's son and would inherit his estate [נתינה לגר, מחוקקי יהודה]. The primary approach among commentators is that Onan acted out of deep selfishness and resentment. He had no desire to invest effort into raising children who would not carry his own legacy [אבן עזרא, בכור שור], nor did he want to share the spiritual merit of the Commandment with his deceased brother [ספורנו]. Some view his actions as pure malice, a deliberate attempt to erase his brother's memory completely [שד״ל]. Furthermore, a strong financial motive drove his behavior. By refusing to produce an heir for his brother, Onan positioned himself to inherit his brother's land, thereby protecting and expanding his own wealth [שד״ל, קונטרס חיבה יתירה, The Torah]. Taking this financial aspect even further, a unique interpretation reads the situation as an agricultural metaphor: Onan refused to expend his literal farming seed and labor to cultivate his brother's land, fearing it would compromise his own inheritance [חזקוני, הדר זקנים].
In his relationship with Tamar, Onan never truly viewed her as his own wife, but strictly as the wife of his brother [ברכת אשר]. In truth, he never wanted to marry her at all. Having been forced into the arrangement by his father, he secretly planned to divorce her eventually, acting deceitfully in the meantime [העמק דבר]. To ensure Tamar would not conceive, Onan engaged in normal marital relations but deliberately withdrew, spilling his seed onto the earth [רש״י, מזרחי, שטיינזלץ]. This physical act of casting his seed to the ground highlights his intentional rejection of his duty and firmly dismisses any notion that he engaged in unnatural acts [אבן עזרא, תורה תמימה].
Interestingly, Onan's older brother, Er, employed the exact same method of preventing pregnancy, yet their underlying motives were entirely different. Er avoided having children simply to preserve Tamar's physical beauty, whereas Onan was driven by financial greed and a refusal to provide continuity for his brother [הדר זקנים]. This distinction highlights a profound difference in their characters: Er was fundamentally a wicked person, whereas Onan's wickedness lay specifically in his actions, which were born out of a selfish fear of personal and financial loss [מלבי״ם].