The crime of Onan wasn't masturbation (obviously), or even birth control... it was attempted theft. He knew that if he got his brother's wife pregnant, the child would inherit. But if the brother's wife was barren, HE would inherit. So, he 'stole' from the 'rightful heir' and was punished.
==================
We should fear God (Matthew 10:28)
We should love God (Matthew 22:37)
There is no fear in love (1 John 4:18)