And the Messenger of Allah, peace and blessings be upon him, said: "Pay special attention to arranging the rows in prayer, for the beauty of prayer depends on the arrangement of the rows."
Hadith Referenceصحيفه همام بن منبه / متفرق / 45
Hadith Takhrij«صحيح بخاري، كتاب الأذان، باب إقامة الصف من تمام الصلوٰة، رقم: 722، حدثنا عبدالله بن محمد: حدثنا عبدالرزاق: أخبر معمر عن همام عن أبى هريرة عن النبى صلى الله عليه وسلم، أنه قال: .... - صحيح مسلم، كتاب الصلوٰة، باب تسوية الصفوف وإقامتها، رقم: 433/124، حدثنا محمد بن رافع: حدثنا معمر عن همام بن منبه، قال: هذا ما حدثنا أبو هريرة عن رسول الله صلى الله عليه وسلم، فذكر أحاديث منها: وقال رسول الله صلى الله عليه وسلم .... - مسند أحمد: 55/16 ، رقم: 45/8142 - مصنف عبدالرزاق: 44/2، باب الصفوف، اختلاف ألفاظ، أقيموا الصفوف .... إقامة الصفوف .... إلخ، رقم: 2424 - شرح السنة: 422/3 وقال: هذا حديث متفق على صحته.»
Narrated Abu Hurairah: The Prophet ﷺ said: Have the imam in the centre and close up the gaps.
Shaykh Umar Farooq Saeedi
681. Commentary: That is, the imam should stand ahead of the rows in such a way that he is in the middle of the congregation (muqtadis), and it should not be that the muqtadis are greater in number on either the right or left side, for in such a case the imam would not remain in the center. The same should be the case for the last row, in which there are only a few individuals; that is, they should not stand at one end of the row, but rather in the middle (with the imam to their right and left), so that the imam remains in the center. However, the first part of this narration is weak, so it can be considered recommended (mustahabb), but not obligatory. As for the second part of the hadith, “Fill the gaps in the rows,” it is authentic, because this command is also established from other ahadith.
Source: Sunan Abu Dawood – Commentary by Shaykh Umar Farooq Saeedi, Page: 681