To elaborate on the sin involved for those who are unfamiliar with the passage...
Genesis 38:1 (TCENB): Onans refusal to give Tamar a child not only demonstrated a lack of love for his deceased brother.
It also revealed Onans selfish heart that wanted for himself what would have gone to his elder brothers heir. If Tamar had born him a son, that child would have been the perpetuator of Ers name as well as that of Onan (cf. Ruth 4:5, 2122).
God judged Onans sin severely because descendants were important in His plans for the patriarchs. Onan was deliberately frustrating the fulfillment of Gods promises to Abraham, Isaac, and Jacob (cf. 11:4).
well and truly stated. And with such focused brevity!