250 صحيح حديث النُّعْمَانِ بْنِ بَشِيرٍ، قَالَ: قَالَ النَّبِيُّ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ : لَتُسَوُّنَّ صُفُوفَكُمْ، أَوْ لَيُخَالِفَنَّ اللهُ بَيْنَ وُجُوهِكُمْ
Sayyiduna Nu'man bin Bashir (may Allah be pleased with them both) narrates that the Noble Prophet (peace and blessings be upon him) said: "Straighten your rows in prayer, otherwise Allah, the Exalted, will turn your faces."
Brief Explanation
Imam Ibn Hazm rahimahullah, based on the apparent meaning of these ahadith, has stated that straightening the rows is obligatory (wajib), whereas according to the majority of scholars, it is Sunnah. The purpose of keeping the rows straight is that they should stand on a single straight line, and not stand ahead or behind one another. (Waheed al-Zaman rahimahullah)