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:4:102

And when you are among them and lead them in prayer, let a group of them stand ˹in prayer˺ with you and let them carry their arms. And when they have prostrated, let them be ˹in position˺ behind you and have the other group come forward which has not ˹yet˺ prayed and let them pray with you, taking precaution and carrying their arms. Those who disbelieve wish that you would neglect your weapons and your baggage so they could come down upon you in one ˹single˺ attack. But there is no blame upon you, if you are troubled by rain or are ill, for putting down your arms, but take precaution. Indeed, Allah has prepared for the disbelievers a humiliating punishment.  

When you, O Muhammad (s), are, present, among them, while you ˹all˺ fear an enemy, and you stand to lead them in prayer (this type of address is customary in the Qur’ān), let a party of them stand with you, while another party stand back, and let them, the party standing with you, take their weapons, with them. Then when they have performed their prostrations, that is, ˹when˺ they have prayed, let them, the other party, be behind you, on guard until you complete the prayers; thereupon, let this party go on guard, and let another party who have not prayed come and pray with you, taking their precautions and their weapons, with them until you have completed the prayers. The Prophet (s) did this once at Batn Nakhla, as reported by the two Shaykhs ˹Bukhārī and Muslim˺. The disbelievers wish, when you have stood up to pray, that you should be heedless of your weapons and your baggage that they may descend upon you all at once, by making an assault against you and capturing you, and herein is the reasoning behind keeping weapons on oneself. You are not at fault, if rain bothers you, or if you are sick, to lay aside your weapons, and not carry them: this implies that when there is no such excuse, it is compulsory to carry them, and this is one of two opinions held by al-Shāfi‘ī ˹on this matter˺; the other ˹opinion˺ is that this ˹precaution˺ constitutes a sunna, and this is the more preferable opinion. But take your precautions, against the enemy and be on your guard as best you can; God has prepared for the disbelievers a humiliating chastisement.
القرآن:٤:١٠٢

وَإِذَا كُنْتَ فِيهِمْ فَأَقَمْتَ لَهُمُ الصَّلَاةَ فَلْتَقُمْ طَائِفَةٌ مِنْهُمْ مَعَكَ وَلْيَأْخُذُوا أَسْلِحَتَهُمْ فَإِذَا سَجَدُوا فَلْيَكُونُوا مِنْ وَرَائِكُمْ وَلْتَأْتِ طَائِفَةٌ أُخْرَىٰ لَمْ يُصَلُّوا فَلْيُصَلُّوا مَعَكَ وَلْيَأْخُذُوا حِذْرَهُمْ وَأَسْلِحَتَهُمْ ۗ وَدَّ الَّذِينَ كَفَرُوا لَوْ تَغْفُلُونَ عَنْ أَسْلِحَتِكُمْ وَأَمْتِعَتِكُمْ فَيَمِيلُونَ عَلَيْكُمْ مَيْلَةً وَاحِدَةً ۚ وَلَا جُنَاحَ عَلَيْكُمْ إِنْ كَانَ بِكُمْ أَذًى مِنْ مَطَرٍ أَوْ كُنْتُمْ مَرْضَىٰ أَنْ تَضَعُوا أَسْلِحَتَكُمْ ۖ وَخُذُوا حِذْرَكُمْ ۗ إِنَّ اللَّهَ أَعَدَّ لِلْكَافِرِينَ عَذَابًا مُهِينًا  

{وإذا كنت} يا محمد حاضرا {فيهم} وأنتم تخافون العدو {فأقمت لهم الصلاة} وهذا جري على عادة القرآن في الخطاب {فلتقم طائفة منهم معك} وتتأخر طائفة {وليأخذوا} أي الطائفة التي قامت معك {أٍسلحتهم} معهم {فإذا سجدوا} أي صلوا {فليكونوا} أي الطائفة الأخرى {من ورائكم} يحرسون إلى أن تقضوا الصلاة وتذهب هذه الطائفة تحرس {ولتأت طائفة أخرى لم يصلوا فليصلوا معك وليأخذوا حذرهم وأسلحتهم} معهم إلى أن تقضوا الصلاة وقد فعل النبي ﷺ كذلك ببطن نخل رواه الشيخان {ودَّ الذين كفروا لو تغفلون} إذا قمتم إلى الصلاة {عن أسلحتكم وأمتعتكم فيميلون عليكم ميلة واحدة} بأن يحملوا عليكم فيأخذوكم وهذا علة الأمر بأخذ السلاح {ولا جُناح عليكم إن كان بكم أذى من مطر أو كنتم مرضى أن تضعوا أسلحتكم} فلا تحملوها وهذا يقيد إيجاب حملها عند عدم العذر وهو أحد قولين للشافعي والثاني أنه سنة ورجح {وخذوا حذركم} من العدو أي احترزوا منه ما استطعتم {إن الله أعد للكافرين عذابا مهينا} ذا إهانة.