Sahih al-Bukhari, Book 95, Hadith 12 (In-Book)

Narrated `Ali: The Prophet, sent an army and appointed some man their commander The man made a fire and then said (to the soldiers), "Enter it." Some of them intended to enter it while some others said, 'We have run away from it (i.e., embraced Islam to save ourselves from the 'fire')." They mentioned that to the Prophet, and he said about people who had intended to enter the fire. ''If they had entered it, they would have remained In it till the Day of Resurrection.'' Then he said to others, "No obedience for evil deeds, obedience is required only in what is good."

حَدَّثَنَا مُحَمَّدُ بْنُ بَشَّارٍ، حَدَّثَنَا غُنْدَرٌ، حَدَّثَنَا شُعْبَةُ، عَنْ زُبَيْدٍ، عَنْ سَعْدِ بْنِ عُبَيْدَةَ، عَنْ أَبِي عَبْدِ الرَّحْمَنِ، عَنْ عَلِيٍّ ـ رضى الله عنه ـ أَنَّ النَّبِيَّ صلى الله عليه وسلم بَعَثَ جَيْشًا وَأَمَّرَ عَلَيْهِمْ رَجُلاً، فَأَوْقَدَ نَارًا وَقَالَ ادْخُلُوهَا‏.‏ فَأَرَادُوا أَنْ يَدْخُلُوهَا، وَقَالَ آخَرُونَ إِنَّمَا فَرَرْنَا مِنْهَا، فَذَكَرُوا لِلنَّبِيِّ صلى الله عليه وسلم فَقَالَ لِلَّذِينَ أَرَادُوا أَنْ يَدْخُلُوهَا ‏"‏ لَوْ دَخَلُوهَا لَمْ يَزَالُوا فِيهَا إِلَى يَوْمِ الْقِيَامَةِ ‏"‏‏.‏ وَقَالَ لِلآخَرِينَ ‏"‏ لاَ طَاعَةَ فِي مَعْصِيَةٍ، إِنَّمَا الطَّاعَةُ فِي الْمَعْرُوفِ ‏"‏‏.‏

sunnah.com