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
Nidah 13b: A Gezerah Shavah between this Pasuk and the Pasuk in Tehilim, "Lo Yegurecha Ra" (Tehilim 5:5) teaches us further that one who indulges in lewd thoughts (which leads to wasting one's seed) will not be brought within the vicinity of Ha'Kadosh-Baruch-Hu.
"One who expresses seed in vain is liable to death (at the hands of Heaven)" (Nidah 13a). Why is this so?
Maharal (Chidushei Agados Vol. 4, p. 153, to Nidah 13a): Seed is the beginning of [any new] existence. Our verse calls wasting it, 'Hashchasa' - demolishing; i.e. uprooting an edifice from its very foundation. One involved in such destruction will himself be destroyed.
"One who expresses seed in vain is as if he brings a Flood upon the world" (Nidah 13a). Why is this so?
Maharal #1 (Chidushei Agados Vol. 4, p. 152-153, to Nidah 13a): Seed is the beginning of existence; one who destroys it is akin to the Mabul, which destroyed all of existence to its very beginning. 1
Maharal #2 (ibid.): The sea was meant to contain the waters of the world, but at the Mabul that boundary was negated, and the world was flooded. So too, in the miniature world that is man, the reproductive organs are to collect the Zera from the body as a whole. 2 Wasting seed is destroying that boundary, akin to a Mabul.
Maharal #3 (ibid.): The Neshamah, before it is attached to a Guf, is over and above the physical; indeed, it can see from one end of the earth to the other. 3 Seed has the potential to receive such a Neshamah; and so wasting it is like the Mabul, which destroyed the world in its entirety.
"One who expresses seed in vain is as if a murderer" (Nidah 13a). Why is this so?
Maharal #1 (Chidushei Agados Vol. 4, p. 153, to Nidah 13a): Seed has the potential to receive a Neshamah; one who wastes it murders the Neshamah that would have joined with this seed. 1
Maharal #2 (ibid.): Seed emanates from the always-flowing Source of life; wasting it is essentially stopping life itself.
Maharal (ibid.): According to Ravina (Sanhedrin 110b), an [unborn] child has a portion in Olam ha'Ba as soon as the seed is generated (and results in conception - Rashi loc. cit).
"One who expresses seed in vain is as if he worships idols" (Nidah 13a). Why is this so?
Maharal (Chidushei Agados Vol. 4, p. 153, to Nidah 13a): Seed is supposed to travel in a central straight line, without veering to the side or going external. Conceptually, the straight path is associated with Hashem, the Source of Life, Who blesses [man's] source. Wasting seed externally is like leaving the straight path and veering after other, external powers ('Chitzonim') so to speak; this is Avodah Zarah.
Rashi (to 5:32) writes that prior to Matan Torah, one was liable to [Divine] punishment only from age 100! If so, why were Er and Onan punished with death?
Refer to 38:7:151:4, and the note there.
It said above (38:7) that Er (i.e. 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'amek 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 (to 38:7), also Er was concerned for a loss, i.e. lest Tamar become pregnant, and less beautiful! (PF)
Why does it say "Im Ba" (if), and not 'Ka'asher Ba' (when)?
Ha'amek 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!