And the thing which he did displeased the LORD: wherefore he slew him also.
What he did was wicked in the sight of the LORD, so He put Onan to death as well.
Read Genesis 38