"You shall circle the city seven times" (Joshua 6:4). One does not lay siege to gentile cities less than three days before Shabbat. This that you say applies to an optional war; but in an obligatory war one may besiege even on Shabbat, for so we find that Jericho was captured only on Shabbat, as it is said, "And on the seventh day you shall circle the city seven times" (Joshua 6:4), and it is written "until it falls" (Deuteronomy 20:20), meaning even on Shabbat.
Circling Jericho Seven Days and the Laws of Sacred War
Yalkut Shimoni on Nach 15:17
תסבו את העיר שבע פעמים (יהושע ו, ד). אין מקיפין עיירות של עו"א פחות משלשה ימים קודם לשבת הא דאת אמר במלחמת הרשות, אבל במלחמת חובה ואפילו בשבת שכן מצינו שלא נלכדה יריחו אלא בשבת שנאמר וביום השביעי תסבו את העיר שבע פעמים וכתיב עד רדתה ואפילו בשבת: