Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:59:14

They will not fight you all except within fortified cities or from behind walls. Their violence among themselves is severe. You think they are together, but their hearts are diverse. That is because they are a people who do not reason.  

They, that is, the Jews, will not fight against you together, ˹all˺ in a ˹single˺ body, except in fortified towns or from behind some wall (jidār: a variant reading has ˹plural˺ judur, ‘walls’), some ˹kind of protective˺ fence. Their might, their belligerence, is great among themselves. You ˹would˺ suppose them to be all together, united as a ˹single˺ body, but their hearts are disunited, scattered, contrary to supposition. That is because they are a people who have no sense;
القرآن:٥٩:١٤

لَا يُقَاتِلُونَكُمْ جَمِيعًا إِلَّا فِي قُرًى مُحَصَّنَةٍ أَوْ مِنْ وَرَاءِ جُدُرٍ ۚ بَأْسُهُمْ بَيْنَهُمْ شَدِيدٌ ۚ تَحْسَبُهُمْ جَمِيعًا وَقُلُوبُهُمْ شَتَّىٰ ۚ ذَٰلِكَ بِأَنَّهُمْ قَوْمٌ لَا يَعْقِلُونَ  

{لا يقاتلونكم} أي اليهود {جميعا} مجتمعين {إلا في قرى محصنة أو من وراء جدار} سور، وفي قراءة جدر {بأسهم} حربهم {بينهم شديد تحسبهم جميعا} مجتمعين {وقلوبهم شتى} متفرقة خلاف الحسبان {ذلك بأنهم قوم لا يعقلون}.