Imām Abū 'Abdullāh Bukhārī said: And Muhammad ibn Yūsuf said to us: Al-Awzā'ī narrated to us, he said: Al-Zuhrī narrated to us, from Humaid ibn 'Abdur-Rahmān, from 'Ubaidullāh ibn 'Adī ibn Khiyār, that he went to 'Uthmān ibn 'Affān, may Allāh be pleased with him, at that time he was confined in his house. He said: Indeed you are the head of all the Muslims, and upon you is that calamity which you see, and a fitnah-raising imām is leading us in prayer, and we are in a difficulty. 'Uthmān said: Prayer is the best good deed of the people, so when the people do good, do good with them, and when they do evil, avoid their evil.
And al-Zubaidī said: Al-Zuhrī narrated that we do not consider it permissible to pray following a mukhannath except in severe necessity.
قَالَ أَبُو عَبْدِ اللَّهِ: وَقَالَ لَنَا مُحَمَّدُ بْنُ يُوسُفَ، حَدَّثَنَا الأَوْزَاعِيُّ، حَدَّثَنَا الزُّهْرِيُّ، عَنْ حُمَيْدِ بْنِ عَبْدِ الرَّحْمَنِ، عَنْ عُبَيْدِ اللَّهِ بْنِ عَدِيِّ بْنِ خِيَارٍ، أَنَّهُ دَخَلَ عَلَى عُثْمَانَ بْنِ عَفَّانَ رَضِيَ اللَّهُ عَنْهُ، - وَهُوَ مَحْصُورٌ - فَقَالَ: إِنَّكَ إِمَامُ عَامَّةٍ، وَنَزَلَ بِكَ مَا نَرَى، وَيُصَلِّي لَنَا إِمَامُ فِتْنَةٍ، وَنَتَحَرَّجُ؟ فَقَالَ: «الصَّلاَةُ أَحْسَنُ مَا يَعْمَلُ النَّاسُ، فَإِذَا أَحْسَنَ النَّاسُ، فَأَحْسِنْ مَعَهُمْ، وَإِذَا أَسَاءُوا فَاجْتَنِبْ إِسَاءَتَهُمْ» وَقَالَ الزُّبَيْدِيُّ، قَالَ: الزُّهْرِيُّ: «لاَ نَرَى أَنْ يُصَلَّى خَلْفَ المُخَنَّثِ إِلَّا مِنْ ضَرُورَةٍ لاَ بُدَّ مِنْهَا»
Reference: Sahih Al Bukhari 695