"What is a levirate marriage?" What was the sin of disobedience Onan committed by "spilling his seed (semen)"

Answer: A levirate marriage is literally a “marriage with a brother-in-law.” The word levirate, which has nothing to do with the tribe of Levi, comes from the Latin word levir, “a husband’s brother.” In ancient times, if a man died without a child, it was common for the man’s unmarried brother to marry the widow in order to provide an heir for the deceased. A widow would marry a brother-in-law, and the first son produced in that union was considered the legal descendant of her dead husband. a good example is the story of Tamar and Onan in Genesis 38. Tamar had been married to Er, a son of Judah. Er died, leaving Tamar childless (Genesis 38:6–7). Judah’s solution was to follow the standard procedure of levirate marriage: he told Er’s brother Onan, “Sleep with your brother’s wife and fulfill your duty to her as a brother-in-law to raise up offspring for your brother” (verse 8). Onan was more than willing to sleep with Tamar, but, unfortunately, he had no desire to have a child with her: “Onan knew that the child would not be his; so whenever he slept with his brother’s wife, he spilled his semen on the ground to keep from providing offspring for his brother” (verse 9). In other words, Onan was taking selfish advantage of levirate marriage. He wanted sex with his sister-in-law, but he purposefully avoided impregnating her. God called Onan’s actions “wicked” and killed him (verse 10). Levirate marriage became part of the Law in Deuteronomy 25:5–6. Another example of levirate marriage in the Bible is the story of Ruth and Boaz.