The story of Judah and Tamar is a carefully placed break in the larger story. It shows what was happening in Judah’s family. Judah would later become an important leader. The story also shows the early stages of the family mixing with the people of the land. This helps explain why God sent the family to Egypt (chapters 39–47).
The Egyptians kept themselves separate from other peoples (43:32). Because of that, the Israelites were more likely to keep their own identity in Egypt than in Canaan.