Genesis 38:9

9 But Onan knew that the children would not belong to him, so when he was supposed to have sexual relations with Tamar he did not complete the sex act. This made it impossible for Tamar to become pregnant and for Er to have descendants.

Genesis 38:9 Meaning and Commentary

Genesis 38:9

And Onan knew that the seed should not be his
Should not be called a son of his, but a son of his brother Er; this is to be understood only of the firstborn; all the rest of the children born afterwards were reckoned the children of the real parent of them; this shows this was a custom in use in those times, and well known, and was not a peculiar case: and it came to pass, when he went in unto his brother's wife;
to cohabit with her, as man and wife, he having married her according to his father's direction: that he spilled [it] on the ground, lest he should give his seed to
his brother:
lest his brother's wife he had married should conceive by him, and bear a son that should be called his brother's, and inherit his estate; and this is the sin, which from him is called Onania, a sin condemned by the light of nature, as well as by the word of God, and very prejudicial to mankind, as well as displeasing to God, as follows:

Genesis 38:9 In-Context

7 But Er, Judah's oldest son, did what the Lord said was evil, so the Lord killed him.
8 Then Judah said to Er's brother Onan, "Go and have sexual relations with your dead brother's wife. It is your duty to provide children for your brother in this way."
9 But Onan knew that the children would not belong to him, so when he was supposed to have sexual relations with Tamar he did not complete the sex act. This made it impossible for Tamar to become pregnant and for Er to have descendants.
10 The Lord was displeased by this wicked thing Onan had done, so the Lord killed Onan also.
11 Then Judah said to his daughter-in-law Tamar, "Go back to live in your father's house, and don't marry until my young son Shelah grows up." Judah was afraid that Shelah also would die like his brothers. So Tamar returned to her father's home.
Scripture taken from the New Century Version. Copyright © 1987, 1988, 1991 by Thomas Nelson, Inc. Used by permission. All rights reserved.