What may not be done during Prayer and what is permitted - Section 2 Mishkat al-Masabih 997

Arabic hadith text
وَعَنْهُ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «يَا بُنَيَّ إِيَّاكَ وَالِالْتِفَاتَ فِي الصَّلَاةِ فَإِنَّ الِالْتِفَاتَ فِي الصَّلَاةِ هَلَكَةٌ. فَإِنْ كَانَ لابد فَفِي التَّطَوُّع لَا فِي الْفَرْضِيَّة» . رَوَاهُ التِّرْمِذِيّ
Translation

He reported God’s Messenger as saying, “Sonny, avoid turning to the side when you are engaged in prayer, for turning to the side produces destruction. If you must do it, do it in the voluntary, but not in the obligatory prayer.”Tirmidhi transmitted it.