It is written, "Ephraim is the stronghold of my head" (Psalms 60:9). If a person says to you, Why did Joshua profane the Shabbat? say to him: The Holy One, blessed be He, told him to, as it is said, "And you shall circle the city... thus shall you do six days... and on the seventh day..." (Joshua 6:3-4), and there are no seven days without a Shabbat. Rabbi Shimon ben Chalafta said: He did one more thing of his own accord, which the Holy One, blessed be He, did not command him. Since he captured it on Shabbat, Joshua said: The Shabbat is holy, and everything we have captured on Shabbat shall be holy. Rabbi Berekhiah said: He treated it like a condemned idolatrous city. But is not a condemned city forbidden in benefit? Rabbi Yehudah HaLevi bar Shalom said in the name of Rabbi Yehoshua: It is written, "The first of your dough you shall give to the LORD" (Numbers 15:21); since we captured it first, let us make it a dough-offering to the Holy One, blessed be He.
Joshua Conquered on Shabbat and Dedicated Jericho as Sacred
Yalkut Shimoni on Nach 15:18
כתיב אפרים מעוז ראשי אם יאמר לך אדם למה חלל יהושע את השבת אמר [לו] הקב"ה (אני) א"ל שנאמר וסבותם את העיר וגו' כה תעשה ששת ימים וגו' וביום השביעי וגו' (יהושע ו, ג-ד) ואין שבעה בלא שבת. אמר רבי שמעון בן חלפתא ועוד דבר אחד עשה מדעתו שלא אמר לו הקב"ה כיון שכבשה בשבת אמר יהושע שבת קדש וכל מה שכבשנו בשבת יהיה קדש. אמר רבי ברכיה כעיר הנדחת עשאה. והרי עיר הנדחת אסורה בהנאה א"ר יהודה הלוי בר שלום אמר רבי יהושע כתיב ראשית עריסותיכם תתנו לה' הואיל וכבשנו אותה תחלה נעשה אותה חלה להקב"ה: