Ge 38:24 And it came to pass, about three months after, that Judah was told, saying, "Tamar your daughter-in-law has played the harlot; furthermore she is with child by harlotry." So Judah said, "Bring her out and let her be burned!"
25 When she was brought out, she sent to her father-in-law, saying, "By the man to whom these belong, I am with child." And she said, "Please determine whose these are -the signet and cord, and staff."
26 So Judah acknowledged them and said, "She has been more righteous than I, because I did not give her to Shelah my son." And he never knew her again.
The incest that Tamar masterminded was wrong. However, the cause behind it was just compared to Judah's. Judah like his son Onan practically did not care to have offspring for descendants. Tamar, on the other hand, wanted a child. Her desire might be that she would have children that would become heirs of the promise made to Abraham.
Moses wants to show his original Israelite readers here the rightness of having descendants. Even Judah had to acknowledge the cause of Tamar as more righteous than his even though it was obtained sinfully.