Here are some useful details in fully understanding the implications of everyone's actions in the story of Judah.
PROSTITUTES IN CANAANAll quoted material is from "Life Application Study Bible" See the sidebar under "Bible Study: Genesis" for links to references used.
Why does this story seem to take a light view of prostitution? Prostitutes were common in pagan cultures such as Canaan. Public prostitutes served the Canaanite goddesses and were common elements of the religious cults. Fornication was encouraged to improve fertility in crops and flocks. They were more highly respected than private prostitutes who were sometimes punished when caught. Tamar was driven to seduce Judah because of her intense desire to have children and be the matriarch of Judah's oldest line; Judah was driven by his lust. Neither case was justified.
WOMEN IN CANAAN
Why was Judah so open about his relations with a prostitute, yet ready to execute his daughter-in-law for being one? To understand this apparent contradiction, we must understand the place of women in Canaan. A woman's most important function was bearing children who would perpetuate the family line. To ensure that children belonged to the husband, the bride was expected to be a virgin and the wife was expected to have relations only with him. If a woman committed adultery, she could be executed. Some women, however did not belong to families. They might be shrine prostitutes supported by offerings or common prostitutes supported by the men who used their services. Their children were nobody's heirs, and men who hired them adulterated nobody's bloodlines.
Judah saw no harm in hiring a prostitute for a night; after all, he was more than willing to pay. He was ready to execute Tamar, however, because if she was pregnant as a result of prostitution, his grandchild would not be part of his family line. Apparently the question of sexual morality never entered Judah's mind; his concern was for keeping his inheritance in the family. Ironically, it was Tamar, not Judah, who acted to provide him with legal heirs. By seducing him, she acted more in the spirit of the law than he did when he refused to send his third son to her.
This story in no way implies that God winks at prostitution. Throughout Scripture, prostitution is condemned as a serious sin If the story has a moral, it is that faithfulness to family obligations is important. Incidentally, Judah and Tamar are direct ancestors of Jesus Christ (Matthew 1:1-6).