God kills a man (onan) for "pulling out" and ejaculating onto the ground thereby avoiding impregnating his partner
- Gen 38:7-10
As background, onan's partner in this affair was his dead brother's wife. According to the text, the reason he was struck down was for "spilling his seed" and not for what he believed to be an adulterous act.
Apparently it never paid to try to use your own judgment of what was right or wrong back in those days. Best to let someone else do your thinking for you.