Abu Sa'id reported God’s Messenger as saying, “When there are three people one of them should lead them. The one among them most worthy to act as imam is the one who is most versed in the Qur’an.”
Muslim transmitted it. The tradition of Malik b. al-Huwairith has been mentioned in a chapter following that on the excellence of the adhan (Ch. 7a).
Malik b. al-Huwairith used to come to our place of prayer and tell us traditions, and one day when the time for prayer came we told him to go forward and lead the prayer, but he said to us: Put one of your own men forward to lead you in prayer, and I shall tell you why I am unwilling to do so. I heard God’s Messenger say, "If anyone visits people he must not act as their imam, but one of their men must do so.”
Abu Dawud, Tirmidhi and Nasa’i transmitted it, but Nasa’i gave only the Prophet's words.
Abu Mas'ud reported God’s Messenger as saying, “The one of you who is most versed in God’s Book should act as imam for the people; but if they are equally versed in reciting it, then the one who has most knowledge regarding the sunna; if they are equal regarding the sunna, then the earliest of them to emigrate; if they emigrated at the same time, then the oldest of them. No man must lead another in prayer where the latter has authority, or sit in his place of honour in his house, without his permission.”
Muslim transmitted it. A version by him has, “And a man must not act as imam for another in his own family.”