This instance of Not In The Bible is a relatively easy one; it just makes remarkably little sense. Setting the scene we have:
If brothers are living together and one of them dies without a son, his widow must not marry outside the family. Her husband's brother shall take her and marry her and fulfill the duty of a brother-in-law to her. The first son she bears shall carry on the name of the dead brother so that his name will not be blotted out from Israel. (Deuteronomy 25:5-6, NIV)Then we have the actual story of Onan.
Judah got a wife for Er, his firstborn, and her name was Tamar. But Er, Judah's firstborn, was wicked in the LORD's sight; so the LORD put him to death.So what we have here is a case of Onan defying one known commandment, and God punishing him; and people who read this tend to ignore the known commandment and instead make up a new one based on whatever in the story they think is gross, and assert that God was punishing Onan for that instead. It's as if people read the story of Cain the farmer murdering his brother Abel the hunter, and decided farming was a sin. It's a wild violation of common sense and Occam's Razor. In fairness, the law about the brother marrying the widow was one of the laws not carried into the Christian Church, and thus many people may not have been familiar with it just like most Christians couldn't tell you offhand whether stork is kosher.
Then Judah said to Onan, "Lie with your brother's wife and fulfill your duty to her as a brother-in-law to produce offspring for your brother." But Onan knew that the offspring would not be his; so whenever he lay with his brother's wife, he spilled his semen on the ground to keep from producing offspring for his brother. What he did was wicked in the LORD's sight; so he put him to death also. (Genesis 38:6-10)
As a note for understanding Onan's motives, I am under the impression that Tamar's son by Onan would have inherited Er's estate, which would otherwise go to Onan and his heirs.