Jacob’s son Judah had three sons: Er, Onan, and Shelah. God killed Er because he thought he was wicked, so Judah told Onan to have children with Er’s widow, Tamar. But if Onan had children with Tamar, they wouldn’t be considered Onan’s children for some reason. So he refused to do it. God thought it was wicked to not impregnate your brother’s wife, so he killed Onan too. Tamar wanted to have children, but Judah wouldn’t let her marry his last son, Shelah.
So Tamar disguised herself and got her father-in-law Judah to agree to pay her to have sex with him, and she got pregnant with twins. When Judah found out that Tamar was guilty of prostitution, he wanted to have her burned to death, but he changed his mind when he realized that he had been her client. Then he decided she was more righteous than him, because he hadn’t let her marry Shelah.
The moral of the story
Prostitution isn’t so bad; it’s no worse than refusing to let someone marry your offspring. And neither is rape by deception, apparently. But if you don’t get your brother’s wife pregnant, you deserve to die!