So people hone in on the "spilling seed" thing and don't read the rest of the story.
God 100% wanted Onan to cuck/get cucked by his dead brother.
If he married his sister-in-law all of his children would be treated like his brother's and would get his inheritance. He's unable to divorce (obviously. God himself told him to do this.) And the implication is he needed to have at least one son to continue the bloodline and inherit the wealth.
He was killed for saying 'no' to this.
A lot of the Old Testament is incredibly specific and doesn't translate at ALL to modern day so it's much easier to pretend it says something else or ignore it entirely.
