This is the issue of one who came late to the prayer being joined by another who also came late. There is a difference of opinion among the scholars as to whether this is allowed or not. Shaykh Muhammad ibn ‘Uthaymeen (may Allaah have mercy on him) was of the view that it is permitted. There follows the text of his comments:
“If two people who came late to the prayer enter (the mosque), and one says to the other, ‘When the imam says the salaam, I will be your imam,’ and the other says, “O.k.,’ then when the imam says the salaam, one of the two becomes the imam for the other. He moves from following an imam to leading the prayer, and the other moves from following one imam to following another.
Some of the scholars said that this is permissible, and that there is nothing wrong with two who missed part of the prayer agreeing that one of them will be the imam for the other. They said that moving from one imam to another is something that is proven in the Sunnah, as in the case of Abu Bakr and the Prophet (peace and blessings of Allaah be upon him), when Abu Bakr led the people in prayer when the Prophet (peace and blessings of Allaah be upon him) was ill, then the Prophet (peace and blessings of Allaah be upon him) came out during the prayer. When Abu Bakr saw him, he stepped back to let the Prophet (peace and blessings of Allaah be upon him) come forward, and the Prophet (peace and blessings of Allaah be upon him) completed the prayer. Narrated by al-Bukhaari, 687; Muslim 418. In this story two transfers took place:
1 – Abu Bakr moved from being the imam to following another imam
2 – The Sahaabah moved from following Abu Bakr to following the Prophet (peace and blessings of Allaah be upon him).
And it was said that this is not permissible, because this involves moving from one imam to another, and moving from following an imam to leading the prayer with no excuse, and it is not possible to move from a lower position to a higher one, because the person who is leading the prayer is in a higher position than the one who is following the imam.
They said: And this was not known at the time of the salaf. The Sahaabah, if they missed a part of the prayer, they did not agree that one of them would step forward and act as an imam for the others. If this was something good they would have done it before us.
But those who say that it is permissible do not say that it is required of those who come late to the prayer to agree that one of them will be the imam. Rather they say that if this is done, it is permissible. There is a difference between saying that it is permissible and saying that it is mustahabb and prescribed in Islam. We do not say that it is prescribed and we do not recommend that if people come late to the prayer, one of them should say, “I will be your imam.” But if they do that, then we do not say, “Your prayer is invalid.” This is the more correct opinion, i.e., that it is permissible, but we should not do it, because it was not known among the salaf, and if something was not known among the salaf, it is better not to do it, because we know that they more keen than us to do what is good, and if something were good they would have done it before us.
Al-Sharh al-Mumti’, 2/316, 317
And Allaah knows best.