Why was Onan Chayav Misah?
Nidah, 13b: Because he spilt his seed on the ground and anyone who spills his seed on the ground is Chayav Misah. 1
It says (verse 7) that Er (himself) was evil in Hashem's eyes. Why does it say here that what Onan did was evil in Hashem's eyes?
Malbim: If one does evil without any intent for benefit or fear of loss, like Er did 1 , he is intrinsically evil. Onan's act was due to a loss - he thought that the child's lineage would not be traced to himself. Only his act was evil.
Ha'Emek Davar: Here, Onan's deed caused his death. Just like he did not want to establish seed for his brother, he would [die, and] not merit to have children.
According to Rashi (verse 7), also Er was concerned for a loss, i.e. lest Tamar become pregnant, and less beautiful! (PF)
Why does it say "Im Ba", and not 'Ka'asher Ba'?
Ha'Emek Davar: He did not want to do Yibum at all, just Yehudah forced him. Even if he did have Bi'ah with her, it was not like his father intended. He intended to divorce her and marry another; he did not intend to be childless his entire life!