I was wondering if there was any special reason the story of Judah and Tamar in Genesis 38 was put in there, it seems such an interruption of the story of Joseph and just doesn’t seem to fit.
I know how you feel, and I used to feel the same way. Then I noticed that it’s right before the story of Joseph and Potiphar’s wife. I now believe that the Lord put the two stories side-by-side to contrast the character of Joseph and his brothers, represented by Judah who convinced them all to sell Joseph into slavery. If you compare the behavior of these two brothers, I think you’ll see what I mean.
Also keep in mind that there are many ways in which Joseph is a model of the Messiah. He was rejected by his brothers, sold as a slave, cast into the pit, and left for dead. But he rose again to become the 2nd most powerful person in the world and saved both his brothers and the gentiles. Along the way he acquired a gentile bride and their children were adopted by his father. Judah and his brothers represent Israel, who rejected and betrayed him, but came to accept him during a time of great tribulation and inherited the land.