The problem with your reasoning is that the bible specifically said why God slew him. Why was he so significant that God “made an example of him,” well, that’s where your context matters. But what was his sin? The bible is specific.
The problem with your reasoning is that you have inferred what the reason is for God slaying him, but it’s not specifically stated as you claim.
Genesis 38:10 states, “What he did greatly offended the LORD, and the LORD took his life too.”
Why exactly was The Lord offended? You claim the Bible specifically states the reason God was offended was simply the act of pulling out, so naturally anytime anybody else does the same God will be offended with them as well.
However, you have neglected to consider the whole context of this passage. Onan was only supposed to have sex with Tamar to produce a child in his late brother’s name. He was only to treat her as wife in order to bring honor to his deceased brother and not just enjoy the act of sex.
Onan’s sin was not fulfilling his family duties and showing great dishonor to his brother by what he did. That is not the case with normal, married couples today. This passage doesn’t say that every other man is forbidden from withdrawing from his wife or that every act of sex must be specifically done in an attempt to procreate.