If two brothers are living together, and one of them dies without having a son, his widow must not marry someone outside her husband’s family. Her husband’s brother must marry her, which is his duty to her as a brother-in-law.
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.
go back, my daughters, to your own homes. I am too old to have another husband. Even if I told myself, ‘I still have hope’ and had another husband tonight, and even if I had more sons,
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.