I asked Messenger of Allah ﷺ about looking hither and thither in prayer. He replied, "It is a way of stealing by which Satan takes away (a portion) from the prayer of a person." (Using translation from Bukhārī 751)
سَأَلْتُ رَسُولَ اللهِ ﷺ عَنِ الِالْتِفَاتِ فِي الصَّلَاةِ قَالَ «اخْتِلَاسٌ يَخْتَلِسُهُ الشَّيْطَانُ مِنَ الصَّلَاةِ» خَالَفَهُ إِسْرَائِيلُ