This chapter can be read as merely an account of the sordid behaviour of Judah, one of the sons of Jacob. Yet because we have the New Testament we know that this chapter actually describes a crucial event in God's longterm preparation for the coming of the Saviour. The ancestor of Jesus would be one of the sons of Judah born to Tamar, a Canaanite .
The chapter begins by describing how Judah took a Canaanite wife by whom he had three sons. This action was contrary to what Isaac and Jacob had done - they had not taken wives from among the pagan Canaanites. Perhaps Judah had left home because he could not cope with the grief of his father over the loss of Joseph and the central role he had played when he suggested that Joseph should be sold to the Ishmaelites.
Judah at this time does not wish to keep any obligation. It was an ancient custom, later included in the law of Israel, that when an eldest brother died childless his next brother should marry the widow in order to continue the family line. Judah knew that his third son should marry Tamar after his two brothers failed to have an heir. Yet he refused to allow this to happen.
Therefore Tamar resorted to an act of deception and tricked Judah into fathering sons through her. Probably, it was done through desperation. Judah, who had deceived his father about Joseph, was now deceived by his daughter-in-law. He was forced to acknowledge publicly that she had acted more righteously than him in this affair. This does not mean that she, at that time, belonged to God's people.
The story highlights three truths. First, God expects us to fulfil our obligations. Second, God is in control of all events, even when those involved in them are disobeying him. Third, the central focus of this event is the coming of the promised Messiah, even although no one then could see it.