Another interpretation: "For My thoughts are not your thoughts" (Isaiah 55:8). As for Joseph, his brothers sold him to the Medanites, and the Medanites sold him to Egypt. Before Joseph went down, Judah went down to prepare the final redeemer, that is, the King Messiah [for from him would come forth the King Messiah]. It is not written here "And Judah went," but rather "And Judah went down" (Genesis 38:1). Rabbi Yochanan said: A going-down was joined to a going-down, the going-down of Joseph to the going-down of Judah; "And Joseph was brought down to Egypt" (Genesis 39:1) and "And Judah went down" (Genesis 38:1). In a like manner you say: "On that very night Belshazzar the Chaldean king was slain" (Daniel 5:30). What is written after it? "And Darius the Mede received the kingdom" (Daniel 6:1). A cutter-off was joined to a cutter-off, a destroyer of a House to a destroyer of a House, and the cessation of a kingdom to the cessation of a kingdom.
Why Judah Went Down When Joseph Was Sold to Egypt
Midrash Tanchuma Buber, Vayeshev 11:3
ד"א כי לא מחשבותי, יוסף מכרו אותו אחיו למדנים והמדנים מכרו אותו אל מצרים, עד שלא ירד יוסף, ירד יהודה להתקין גואל אחרון זה מלך המשיח [שיצא ממנו מלך המשיח], וילך יהודה אין כתיב כאן, אלא וירד יהודה, אמר ר' יוחנן נסמך ירידה לירידה, ירידת יוסף לירידת יהודה, ויוסף הורד מצרימה וירד יהודה, כיוצא בדבר אתה אומר ביה בליליא קטיל בלשצר מלכא כשדאה (דניאל ה ל), מה כתיב אחריו, ודריוש מדאה קביל מלכותא (שם ו א), נסמך קוצץ לקוצץ, מחריב בית למחריב בית והפסק מלכות להפסק מלכות.