"And the sun was silent and the moon stood still — is this not written in the Book of Jashar?" (Joshua 10:13). Rabbi Chalafai brought support for this from here: "and to rule over the day and over the night" (Genesis 1:18) — these are the righteous, who rule over what was created to give light by day and over what was created to give light by night. Rabbi Chanan in the name of Rabbi Shmuel bar Rav Yitzchak brings it from the end of the book [of the Torah's blessing of Joseph]: "but his younger brother shall be greater than he, and his seed shall fill the nations [melo ha-goyim]" (Genesis 48:19). Is such a thing possible [literally, that his seed fill the nations]? Rather, this refers to Joshua, who arose from him, who stops the orb of the sun and the moon, which rule from one end of the world to the other. And there are those who bring it from the end of the Torah: "the firstborn of his ox, majesty is his" (Deuteronomy 33:17). Is it possible to say so? Rather, this refers to Joshua, who arose from him, and so forth, as above. Rabbi Shimon son of Yochai said: It was the book of Deuteronomy. Joshua's deputy took it and showed it to the orb of the sun, and said to it: Just as I have not been silent from this [study of Torah], so too be silent before me. Rabbi Elazar said in the name of Rabbi Yitzchak: He said to it, "Wicked slave, did you not buy yourself with my father's silver?" — that is, did not my father so behold you in a dream, "and behold, the sun and the moon and eleven stars were bowing down to me" (Genesis 37:9)?
The Righteous Who Rule Over the Sun and Moon
Yalkut Shimoni on Nach 22:2
וידום השמש וירח עמד הלא היא כתובה על ספר הישר (יהושע י, יג). ר' חלפיי אייתי ליה מהכא ולמשול ביום ובלילה אלו צדיקים שהם שולטין במה שנברא להאיר ביום ובמה שנברא להאיר בלילה. ר' חנן בש"ר שמואל בר רב יצחק מייתי לה מסיפא דספרא ואולם אחיו הקטן יגדל ממנו וזרעו יהיה מלא הגוים אפשר כן, אלא זה יהושע שעומד ממנו שהוא מעמיד גלגל חמה ולבנה שהם שליטים מסוף העולם ועד סופו. ואית דמייתי לה מסיפא דאורייתא בכור שורו הדר לו וגו', אפשר לומר כן אלא זה יהושע שעומד ממנו כו' (כדלעיל). אר"ש בן יוחאי ספר משנה תורה היה (שגנז [סגנו] של יהושע נטולו והראהו לגלגל חמה א"ל כשם שלא דממתי מזה אף שום מלפני. ר"א יצחק א"ל עבדא בישא לא זבינת כספא דאבא את לא כך ראה אותך אבא בחלום והנה השמש והירח ואחד עשר כוכבים משתחוים לי: