Rabbi Shmuel son of Rabbi Yitzchak derives it from the end of the book: "and his younger brother shall be greater than he, and his seed shall become a multitude of nations" (Genesis 48:19). Is this possible? Rather, this is Joshua, who arose from him, who made the sun and the moon stand still, which rule from one end of the world to the other. Rabbi Chanan derives it from the end of the Torah, as it is said, "the firstborn of his ox, majesty is his, and his horns are the horns of a wild ox; with them he shall gore the peoples together, to the ends of the earth" (Deuteronomy 33:17). Is this possible? Rather, this is Joshua son of Nun. Rabbi Shimon ben Yochai said: The book of Deuteronomy was a standard for Joshua. When the Holy One, blessed be He, revealed Himself to him, He found him sitting with the book of Deuteronomy in his hand. He said to him: Be strong, Joshua, be courageous, Joshua, "this book of the Torah shall not depart from your mouth" (Joshua 1:8). He took it and showed it to the orb of the sun and the moon. He said to them: Just as I did not fall silent from this, so you too be silent before me. Immediately, "the sun stood still and the moon stayed." He said to them: Wicked servant, did you not buy my father's silver? Did my father not see you in a dream, "and behold the sun and the moon and eleven stars" (Genesis 37:9)? Immediately, "the sun stood still and the moon stayed."
Joshua Halts the Sun and Rebukes It With Joseph's Dream
Yalkut Shimoni on Torah 11:1
רַבִּי שְׁמוּאֵל בְּרַבִּי יִצְחָק, מַיְּתֵי לֵיהּ מִסֵּיפֵיהּ דְּסִפְרָא (בראשית מח, יט) "וְאוּלָם אָחִיו הַקָּטָן יִגְדַּל מִמֶּנּוּ וְזַרְעוֹ יִהְיֶה מְלֹא הַגּוֹיִם", אֶפְשָׁר כֵּן אֶלָּא זֶה יְהוֹשֻׁעַ שֶׁעָמַד מִמֶּנּוּ שֶׁהוּא מַעֲמִיד חַמָּה וּלְבָנָה שֶׁהֵן שׁוֹלְטִין מִסּוֹף הָעוֹלָם וְעַד סוֹפוֹ. רַבִּי חָנָן מַיְּתֵי לֵיהּ מִסֵּיפֵיהּ דְּאוֹרַיְתָא שֶׁנֶּאֱמַר "בְּכוֹר שׁוֹרוֹ הָדָר לוֹ וְקַרְנֵי רְאֵם קַרְנָיו בָּהֶם עַמִּים יְנַגַּח יַחְדָּו אַפְסֵי אָרֶץ", אֶפְשָׁר כֵּן אֶלָּא זֶהוּ יְהוֹשֻׁעַ בִּן נוּן אָמָר רַבִּי שִׁמְעוֹן בֶּן יוֹחָאי, סֵפֶר מִשְׁנֵה תּוֹרָה הָיָה סִגְנוֹן לִיהוֹשֻׁעַ בְּשָׁעָה שֶׁנִּגְלָה עָלָיו הַקָּדוֹשׁ בָּרוּךְ הוּא מְצָאוֹ יוֹשֵׁב וְסֵפֶר מִשְׁנֵה תּוֹרָה בְּיָדוֹ. אָמַר לוֹ, חֲזַק יְהוֹשֻׁעַ, אֱמַץ יְהוֹשֻׁעַ (יהושע א, ח) "לֹא יָמוּשׁ סֵפֶר הַתּוֹרָה הַזֶּה מִפִּיךָ". נְטָלוֹ וְהֶרְאָהוּ גַּלְגַּל חַמָּה וּלְבָנָה. אָמַר לָהֶם, כְּשֵׁם שֶׁלֹּא דֹּמַמְתִּי מִזֶּה אַף אַתֶּם דֹּמּוּ מִפָּנַי, מִיָּד "וַיִּדֹּם הַשֶּׁמֶשׁ וְיָרֵחַ עָמַד". אָמַר לָהֶם, עַבְדָּא בִּישָׁא, לָא זְבִינַת כַּסְפָּא דְאַבָּא אַתְּ לֹא כָּךְ רָאָה אוֹתָךְ אַבָּא בַּחֲלוֹם (בראשית לז, יט) "וְהִנֵּה הַשֶּׁמֶשׁ וְהַיָּרֵחַ וְאַחַד עָשָר כּוֹכָבִים" וְגוֹ' מִיָּד "וַיִּדֹּם הַשֶּׁמֶשׁ וְיָרֵחַ עָמַד".