Judah had 3 sons, Er, Onan, and Shelah. When the eldest son got old enough for marriage, Judah set up a wife for Er with a woman named Tamar. But Er died because he was wicked (God killed him), so Judah had Onan take Tamar to be his wife and to raise a child in the name of Onan's dead brother; after all, keeping one's name alive for generations was highly prized in Israel.
But Onan didn't want to have a son that wouldn't belong to him, so when he was having sex with Tamar he pulled out last minute and she did not get pregnant. And because he didn't fulfill his duty to the widow God killed him too.
From Judah's point of view, his two oldest sons had one wife, and both sons died while in the embrace of that same wife. It seemed obvious that she was probably the reason for both of his sons' deaths - she was a black widow. Later Jewish literature comments on this. From myjewishlearning.com, Rabbi Dr. Louis Jacobs writes:
The Talmud (Yevamot 64b) observes that it is dangerous to marry a woman who has been widowed from two former husbands, either because she may have some malignant disease in her womb which caused their deaths or because it may be her fate not to have a husband to support her. The second view is applicable to cases where the woman was widowed from her first two husbands without having lived with them or where the death was due to an accident.
Years later, Jacob refused to let his youngest son go near her, which was important for the day, so in order for her to get a child she dressed up as a prostitute hiding her face under a veil, knowing that her father-in-law would give in to his lusts. She was right, and he had sex with her thinking she was a prostitute, and Tamar got pregnant. But when Judah heard that she dressed up as a prostitute in order to get pregnant, he wanted her killed.I believe his desire to kill Tamar was steeped with revenge for the deaths of his sons. He had transfered all the anger from the loss of his two sons to Tamar.
Nevertheless, when the truth came out that Tamar had seduced him, Judah realized that she had acted rightously. Perhaps then, he was willing to admit that she was not the one who killed his sons. But then again, maybe not.