فَإِنْ صَلَّى الْإِمَامُ فِيهَا بِجَمَاعَةٍ، فَجَعَلَ بَعْضُهُمْ ظَهْرَهُ إِلَى ظَهْرِ الْإِمَامِ: جَازَ.
Translation: If the imam leads a congregation inside and some followers place their backs toward the imam’s back, it is valid.
The imam and the followers may face different internal sides of the Kaaba. Being back-to-back does not itself invalidate following, since each is facing a part of the Kaaba.
This is a special situation and cannot automatically be applied to ordinary straight rows in a mosque.