Fiqh-us-Sunnah Volume 2, Supererogatory Prayer, Fiqh 2.054.
If the regular imam or appointed imam is not present, it is permissible to appoint someone else to perform the duty of imam. If the regular imam appears during the prayers, the substitute imam may move back to the rows and allow the regular imam to take over. Al-Bukhari and Muslim record that Sahl ibn Sa’d said: “The Messenger of Allah sallallahu alehi wasallam went off to take care of the affairs of the tribe of ‘Amr ibn ‘Auf. The time for salah came and the mu’azhzhin went to Abu Bakr and said: ‘Will you lead the people in salah and I shall make the iqamah?’ Abu Bakr agreed. [While he was] leading the prayer, the Messenger of Allah appeared and joined the rows. The people clapped [their thighs with their hands] but Abu Bakr would not turn around during the prayer. When most of the people began clapping, he turned and saw the Prophet…[who] pointed to Abu Bakr to stay in his place. Abu Bakr raised his hands and praised Allah because of what the Prophet had told him. Then, Abu Bakr moved back until he joined the rows and the Prophet stepped forward [to lead]. After he had prayed, he went to Abu Bakr and said: O Abu Bakr, what prevented you from staying there when I told you to do so?’ Abu Bakr said: ‘It is not fit for the son of Abu Quhafah to lead the Prophet in prayer.’ Then the Messenger of Allah said: ‘Why did I see most of you clapping? If you find something in the prayer you should say subhanallah, for when you say it, it will attract his (i.e. imam’s) attention and clapping [thighs with hands] is for the women.'”