If two or more are equal in this, then it is the one who has the most knowledge of the sunnah. If they are equal in that, then it is the one who performed the migration first. If they are equal in that, then it should be the eldest.
Abu Sa’id narrates that the Prophet said: “If you are three in number, then one of you should be the imam. And the one who has the most right to it is the one who is the most versed in the Qur’an.” This is related by Ahmad, Muslim, and an-Nasa’i. The meaning of “most versed in the Qur’an” is the one who has more of the Qur’an memorized. This interpretation is based on the hadith from Amr ibn Salamah which says: “Your imam should be the one who is most versed in the Qur’an.”
Ibn Mas’ud reports that the Prophet sallallahu alehi wasallam said: “The imam of a people should be the one who is the most versed in the Book of Allah. If they are equal in their recital, then the one who is most knowledgeable of the sunnah. If they are equal in the sunnah, then [it is] the one who migrated first. If they are equal in that, then [it is] the eldest. And no man should be an imam for another man if the other holds authority [i.e., a leader in any capacity or ruler of the Muslim people]. And one should not occupy his place of honour in his house without his permission.” In another narration it is stated: “No man should be the imam for another while with the other’s family or where the other is in authority.” This is related by Ahmad and Muslim.
As stated earlier, it is better for women to pray in their houses. Ahmad and at-Tabarani record that Umm Humaid as-Sa’diyah came to the Messenger of Allah and said: “O Messenger of Allah, I love to pray with you.” The Prophet said: “I am aware of that, but your salah in your residence is better for you than your salah in your people’s mosque. And your salah in your people’s mosque is better than your salah in the [larger] congregational Mosque.”
Sa’id ibn Mansur says: “A person should not be an imam for another where the other is in authority except with his permission.” The meaning of this is that the one in authority, owner of a house, leader of a meeting, and so on, has more right than others to be the imam if he has not granted the permission to any of the others. Abu Hurairah reports that the Prophet sallallahu alehi wasallam said: “It is not allowed for a man who believes in Allah and the last day to be an imam for a people, except with their permission, nor may he specifically make supplications for himself without including them. If he does so, he is disloyal to them.” This is related by Abu Dawud.