"And she caught him by his garment, and he fled and went outside" (Genesis 39:12). He leaped by the merit of the fathers, as you say, "And He brought him outside" (Genesis 15:5). Shimon of Kitron says: By the merit of Joseph's bones the sea split before Israel, as it says, "The sea saw and fled" (Psalms 114:3) — by the merit of "and he fled and went outside." "And she called to the men of her house" (Genesis 39:14) — she put him on the lips of all of them. "And she laid his garment beside her" (Genesis 39:16) — she embraced and kissed it. "Your servant did to me according to these words" (Genesis 39:19) — she said it to her husband at the time of intimacy. "And Joseph's master took him" (Genesis 39:20) — he said to him, "I know that it was not from you; only that I may not mix dross among my children." Rav Huna said: His service was pleasing to his master; he would go out and rinse the cups and arrange the tables and make the beds. She would say to him, "With this matter I have occupied you; by your life, I will oppress you with other matters," and he would answer, "He executes judgment for the oppressed" (Psalms 146:7). "I will cut off your rations," and he would answer, "He gives bread to the hungry." "I will put you in chains," and he would answer, "The LORD releases the bound." "I will blind your eyes," and he would answer, "The LORD opens the eyes of the blind." "I will bend your stature," and he would answer, "The LORD raises up those bowed down." To what extent? Until she placed an iron fork beneath his neck so that he would lift his eyes and look at her; even so he would not look at her, as it is written, "His soul came into iron" (Psalms 105:18). ("And the warden of the prison gave into Joseph's hand" — his service was pleasing to his master; he would go out and rinse the cups and arrange the tables and make the beds for him.) Joseph went down to Egypt and spent twelve months in Potiphar's house, as it says, "And it was from the time he appointed him in his house" — "in the house" because of the heat, "in the field" because of the cold. Twelve years he spent in prison, as it says, "They afflicted his foot with the fetter" (Psalms 105:18). "And Joseph was thirty years old when he stood," and so on. At that very period Isaac died. The seven years of plenty and two years of famine — Joseph was separated from his father, not seeing him for twenty-two years, just as Jacob was separated from his father.
Joseph Fled Outside and the Sea Fled Before Israel
Yalkut Shimoni on Torah 146:4
(בראשית לט יב) וַתִּתְפְּשֵׂהוּ בְּבִגְדוֹ וְגוֹ' וַיָנָס וַיֵּצֵא הַחוּצָה. קָפַץ בִּזְכוּת אָבוֹת כְּמָה דְּאַתְּ אָמַר (בראשית טו, ה) "וַיּוֹצֵא אֹתוֹ הַחוּצָה". שִׁמְעוֹן אִישׁ קִטְרוֹן אוֹמֵר, בִּזְכוּת עַצְמוֹתָיו שֶׁל יוֹסֵף קָרַע הַיָּם לִפְנֵי יִשְׂרָאֵל, שֶׁנֶּאֱמַר (תהלים קיד, ג) "הַיָּם רָאָה וַיָּנֹס", בִּזְכוּת וַיָּנָס וַיֵּצֵא הַחוּצָה. (בראשית לט יד) וַתִּקְרָא לְאַנְשֵׁי בֵיתָהּ. נָתְנָה אוֹתוֹ בְּפִיהֶם שֶׁל כֻּלָּם. (בראשית לט טז) וַתַּנַּח בִּגְדוֹ אֶצְלָהּ. מְחַבַּקְתּוֹ וּמְנַשַּׂקְתּוֹ. (בראשית לט יט) כַּדְּבָרִים הָאֵלֶּה עָשָה לִי עַבְדֶּךָ. אָמְרָה לוֹ בִּשְׁעַת תַּשְׁמִישׁ. (בראשית לט כ) וַיִּקַּח אֲדֹנֵי יוֹסֵף אֹתוֹ. אָמַר לוֹ, אֲנָא יָדַע דְּלֵית הוּא מִנָּךְ, אֶלָּא שֶׁלֹּא לְעָרֵב פְּסֹלֶת בְּבָנַי. (בראשית לט כא-כב) רַב הוּנָא אָמַר שִׁמּוּשׁוֹ הָיָה עָרֵב לְרַבּוֹ, וְהָיָה יוֹצֵא וּמֵדִיחַ אֶת הַכּוֹסוֹת וְעוֹרֵךְ אֶת הַשֻּׁלְחָנוֹת וּמַצִּיעַ הַמִּטוֹת וְהָיְתָה אוֹמֶרֶת לוֹ בְּדָבָר זֶה עֲסַקְתִּיךָ חַיֶּיךָ אֲנִי עוֹשַקְתְּךָ בִּדְבָרִים אֲחֵרִים וְהוּא אוֹמֵר (תהלים קמו, ז) עֹשֶׂה מִשְׁפָּט לַעֲשׁוּקִים. חוֹתֶכֶת אֲנִי אֲנוּנָא שֶׁלְךָ, וְהוּא אוֹמֵר "נֹתֵן לֶחֶם לָרְעֵבִים". כּוֹבַלְתְּ(י)ךָ אֲנִי, וְהוּא אוֹמֵר (שם) "ה' מַתִּיר אֲסוּרִים". מְסַמָּא אֲנִי אֶת עֵינֶיךָ, וְהוּא אוֹמֵר "ה' פֹּקֵחַ עִוְרִים". כּוֹפֶפֶת אֲנִי קוֹמָתְךָ, וְהוּא אוֹמֵר (שם) "ה' זֹקֵף כְּפוּפִים". עַד הֵיכָן עַד שֶׁנָּתְנָה שִׁרְתּוּעַ שֶׁל בַּרְזֶל תַּחַת צַוָּארוֹ כְּדֵי שֶׁיִּתְלֶה עֵינָיו וְיַבִּיט בָּהּ, אַף עַל פִּי כֵן לֹא הָיָה מַבִּיט בָּהּ, הֲדָא הוּא דִּכְתִיב (שם קה, יח) "בַּרְזֶל בָּאָה נַפְשׁוֹ". (וַיִּתֵּן שַׂר בֵּית הַסֹּהַר בְּיַד יוֹסֵף. שִׁמּוּשׁוֹ הָיָה עָרֵב לְרַבּוֹ הָיָה יוֹצֵא וּמֵדִיחַ אֶת הַכּוֹסוֹת וְעוֹרֵךְ שֻׁלְחָנוֹת וּמַצִּיעַ לוֹ אֶת הַמִּטוֹת). יָרַד יוֹסֵף לְמִצְרַיִם וְעָשָׂה בְּבֵית פּוֹטִיפַר שְׁנֵים עָשָׂר חֳדָשִׁים, שֶׁנֶּאֱמַר "וַיְהִי מֵאָז הִפְקִיד אֹתוֹ בְּבֵיתוֹ" "בַּבַּיִת" מִפְּנֵי הַחַמָּה "בַּשָּׂדֶה" מִפְּנֵי הַצִּנָה שְׁנֵים עָשָׂר שָׁנָה עָשָׂה בְּבֵית הָאֲסוּרִין שֶׁנֶּאֱמַר (תהלים קה, יח) "עִנּוּ בַכֶּבֶל רַגְלוֹ". "וְיוֹסֵף בֶּן שְׁלֹשִׁים שָׁנָה בְּעָמְדוֹ" וְגוֹ'. בּוֹ בַּפֶּרֶק מֵת יִצְחָק וְשֶׁבַע שְׁנֵי הַשֹּׂבַע וּשְׁתֵּי שְׁנֵי הָרָעָב נִמְצָא יוֹסֵף פֵּרֵשׁ מֵאָבִיו, שֶׁלֹּא רָאָהוּ עֶשְׂרִים וּשְׁתַּיִם שָׁנָה, כְּשֵׁם שֶׁפֵּרֵשׁ יַעֲקֹב מֵאָבִיו.