וַֽיְהִי֙ בָּעֵ֣ת הַהִ֔וא וַיֵּ֥רֶד יְהוּדָ֖ה מֵאֵ֣ת אֶחָ֑יו וַיֵּ֛ט עַד־אִ֥ישׁ עֲדֻלָּמִ֖י וּשְׁמ֥וֹ חִירָֽה׃
Il arriva, en ce temps là, que Juda s’éloigna de ses frères et s’achemina vers un habitant d’Adoullam, nommé Hira.
Rashi
ויוסף הורד AND JOSEPH WAS BROUGHT DOWN — It (Scripture) now reverts to the original subject (and consequently it states ויוסף הורד “Joseph had been brought down to Egypt” before the events last mentioned); it interrupted it only in order to connect the account of the degradation of Judah (Genesis 38:1) with that of the sale of Joseph, thus suggesting that it was on account of him (i.e. Joseph — Judah’s part in the sale of Joseph — ) that they (his brothers) degraded him from his high position. A further reason why this narrative of Judah and Tamar is interpolated here is to place in juxtaposition the story of Potiphar’s wife and the story of Tamar, suggesting that just as this woman (Tamar) acted out of pure motives so also the other (Potiphar’s wife) acted out of pure motives, for she foresaw by her astrological speculations that she was destined to be the ancestress of children by him (Joseph) — but she did not know whether these children were to be hers or her daughter’s (Genesis Rabbah 85:2).
Chizkuni
ויוסף הורד מצרימה, “meanwhile Joseph had been transported toward Egypt;” before the first Israelite became enslaved the eventual redeemer had been born. Peretz who was destined to become the ancestor of the Mashiach was born, and only after that does the Torah report about Joseph becoming a slave in Egypt. [Joseph clearly had been brought to Egypt about 21 years earlier, as we demonstrated in our commentary on Genesis 38,1. Ed.] Joseph was the first Israelite to become enslaved.
Siftei Chakhamim
Also, in order to relate the narrative of Potiphar’s wife to the narrative of Tamar... You might ask: Why did Rashi not explain this before, at the beginning of the section (38:1)? There, Rashi asks why Scripture interrupted to tell the narrative of Yehudah, and Rashi explains only that “his brothers demoted him,” but he did not bring this alternate explanation. The answer is: Before, one could have objected: how does Rashi know that Tamar had pure motives? But now that Rashi proves that her motive were pure, from the verse, “She is righteous, it is from me,” he therefore brings the explanation here. (Kitzur Mizrachi) Question: According to the first explanation, Scripture should have only interrupted [by telling the narrative of Yehudah] until, “Many days passed ... the wife of Yehudah died...” (38:12), where a different episode begins. Why did it not [return and] finish the narrative of Yoseif at that point? Rashi answers, “In order to connect the narrative of Potiphar’s wife to the narrative of Tamar.” But with this explanation only, [a question arises:] The narrative of Yehudah should begin with, “Many days passed ... the wife of Yehudah died...” Why begin with, “Yehudah descended from his brothers” (38:1)? [The answer is:] Perforce, to indicate that they demoted Yehudah. Accordingly, at the beginning of the section Rashi is explaining only why “Yehudah descended from his brothers” follows after Yoseif’s sale. Thus he wrote only the first explanation. But here Rashi is explaining the reason for the entire interruption, so he brings both explanations. (Gur Aryeh)