Genesis 38 tells the story of Judah and Tamar. At first Tamar was married to Er (Judah's firstborn son) but he was wicked and killed by the Lord v6-7. So Judah tells Tamar to wait until his youngest son, Shelah, grows up v11 (to marry her?). Years go by and Tamar is never given to Shelah as a wife so Tamar disguises herself as a prostitute and Judah sleeps with her since he doesn't recognize her. When he finds out she's pregnant, he wants her burned to death but she proves he is the one who impregnated her to which Judah replies, "She is more righteous than I, since I wouldn’t give her to my son Shelah" v26.
Why does Judah say that Tamar is more righteous than himself? I feel like I'm missing something.