The punishment for all that, with all the spin you’d like to put on it, was for the widow to remove his shoe publicly and spit on him. Not death.
Incorrect. The punishment for refusing to LAY with her was what you described. In essence, he raped her. The punishment for that is quite a bit more severe...
The closest I know of for a man & wife having intercourse but withdrawing beforehand would be Lev 15:
“If a man lies with a woman and has an emission of semen, both of them shall bathe themselves in water and be unclean until the evening.”
The concern in context was with touching semen, but that is about as specific as scripture gets. There is nothing in Onan’s case that resembles a man using a condom when lying with his wife.