Permissibility of concealing one's faith in the case of fear
باب جَوَازِ الاِسْتِسْرَارِ لِلْخَائِفِ
Sahih Muslim, Book of The Book of Faith(view book)
Sahih Muslim 149
Hudhaifa reported: We were in the company of the Messenger of Allah ﷺ when he said. Count for me those who profess al-Islam. We said: Messenger of Allah, do you entertain any fear concerning us and we are (at this time) between six hundred and seven hundred (in strength). He (the Holy Prophet) remarked: You don't perceive;
you may be put to some trial, He (the narrator) said: We actually suffered trial so much so that some of our men were constrained to offer their prayers in concealment.
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، وَمُحَمَّدُ بْنُ عَبْدِ اللَّهِ بْنِ نُمَيْرٍ، وَأَبُو كُرَيْبٍ - وَاللَّفْظُ لأَبِي كُرَيْبٍ - قَالُوا حَدَّثَنَا أَبُو مُعَاوِيَةَ، عَنِ الأَعْمَشِ، عَنْ شَقِيقٍ، عَنْ حُذَيْفَةَ، قَالَ كُنَّا مَعَ رَسُولِ اللَّهِ ﷺ فَقَالَ " أَحْصُوا لِي كَمْ يَلْفِظُ الإِسْلاَمَ " . قَالَ فَقُلْنَا يَا رَسُولَ اللَّهِ ﷺ أَتَخَافُ عَلَيْنَا وَنَحْنُ مَا بَيْنَ السِّتِّمِائَةِ إِلَى السَّبْعِمِائَةِ قَالَ " إِنَّكُمْ لاَ تَدْرُونَ لَعَلَّكُمْ أَنْ تُبْتَلَوْا " . قَالَ فَابْتُلِينَا حَتَّى جَعَلَ الرَّجُلُ مِنَّا لاَ يُصَلِّي إِلاَّ سِرًّا .