كتاب المقدمات
The Book of Miscellany
(44)
Chapter: Revering the Scholars and Elders, Preferring them to others and raising their Status
(44)
- باب توقير العلماء والكبار وأهل الفضل وتقديمهم على غيرهم، ورفع مجالسهم، وإظهار مرتبتهم
Riyad as-Salihin 349
Abu Mas'ud Al-Ansari (May Allah be pleased with him) reported:
Messenger of Allah (ﷺ) would place his hands upon our shoulders when we would form rows for As-Salat (the prayer) and say, "Stand in straight rows and do not differ among yourselves, or else your hearts will differ due to disaccord. Let those be nearest to me who are mature and endowed with understanding (of the religion), then those who are nearest to them in these respects and then those who are nearest to them".

[Muslim].
وعنه قال‏:‏ كان رسول الله صلى الله عليه وسلم يمسح مناكبنا في الصلاة ويقول‏:‏ ‏ "‏استووا ولا تختلفوا، فتختلف قلوبكم، ليلني منكم أولو الأحلام والنهى، ثم الذين يلونهم‏"‏ ‏(‏‏(‏رواه مسلم‏)‏‏)‏‏.‏
Reference : Riyad as-Salihin 349
In-book reference : Introduction, Hadith 349