Four opinions regarding when this story occurred
Va'y'hi bo'eis hahee va'yei'red Yehudah" - And it was at that time and Yehudah descended (38,1)
Parshas VaYashev deals with the events involving Yosef being brought to Egypt and what happened there, which is continued in the following Parshious. However, the narrative is “interrupted” by Yehudah’s family issued in Chaprter 38. The problem is that 22 years is very short period for his family to produce three generations.
- Yosef was sold (Chapter 37) 17 years old
- Yosef went to jail (Chapter 39) 18 years old
- Yosef was in jail for 12 years
- Yosef stood before Paroh (Chapter 40) 30 years old
- Seven good years and first 2 famine years
- Yaacov when to Mitrzaim with the 70 souls which included the children of Peretz, son of Yehudah 39 years old
Opinion 1: Chronological Sequence (Seder Olam, Chizkuni, Medrash HaGadol)
A simple reading of Chumash is understood that Chapter 38 (story of Yehuda) is this next incident taking place right around the time of the sale of Yosef. Rashi clearly states this by saying that "Va'yei'red Yehudah" means that he was demoted because he did not stand up to his brothers and dissuade them from selling Yosef.
Given that twenty-two years later the tribes descended to Egypt with all of Yaakov's household, we have an extremely difficult problem with this time line. Yehudah had two sons (Eir, Onan) and they grew sufficiently to marry Tamar. Yehudah eventually sired through Tamar: Peretz and Zerach. Peretz was the father of Chetzron and Chomul. Chetzron and Chomul are listed among those who descended to Egypt. All this took place in a 22 years span requiring Er, Onan, and Peretz got married when they were seven and become a father at 8 years old.
The Gemara (Sanhendrin 69b) does discuss the possibility of becoming a father at this young age. This would be a solution if Yehudah married right after the sale of Yosef, then married his oldest sons when they were seven, then impregnated Tamar after 10 years after the sale (one year each for the pregnancy/birth of the eldest sons, seven years till then became fathers, and one year till Tamar waited for Shailia; see Bereshis Rabbah 85:6 and Nazir 4b-5a). This leaves 12 years for Peretz to be born and have two children. This might be likely if we have three fathers that shared the same genes.
As difficult as this is, and commentators do clarify it, at least we have an understanding of why this incident is placed here, as it was chronologically correct, notwithstanding that if we are in the middle of an incident, we usually continue with it, and later deal with other things.
Opinion 2: Yehudah got married prior to the sale of Yosef (B.R., Tur, Ibn Ezra, Rabbeinu Bachyei, and Rabbi Avrohom ben haRambam, Ralbag)
Yehudah married prior to the sale. Yehudah was at most four years older than Yosef and 21 at the time of the sale of Yosef, he was married very young, but adding up to 6 years to the time frame. Plus, he left the family at the time of the birth of Shalia, the third son, to attend to Yaacov’s affairs that lead to the sale of Yosef. This lead to the future “problems” and resolution with Tamar.
This would slightly alleviate the timeline issue. Of course, this exacerbates the issue of the interruption of Yosef's odyssey. Some say that the Torah wanted to place the unsavory business of the wife of Poti Phera and Yosef and that of Yehudah and Tamar side by side, as in both situations the woman had "shem Shomayim in mind." Rabbeinu Bachyei writes that they are to be placed next to each other because of the common theme of reincarnation, "gilgul." The quasi-"yibum" of Tamar and the death of the "Asoroh harugei malchus" both are steeped in this concept.
