Praise be to Allah.
If a third person comes and joins two who are praying, then the one who is praying behind the imaam should move back, because of the report narrated by Muslim, in al-Saheeh (no. 3010), from Jaabir who said: “The Messenger of Allaah (peace and blessings of Allaah be upon him) stood up to pray, and I came and stood on his left. He took my hand and turned me around until I was standing on his right. Then Jabbaar ibn Sakhr came and stood on the left of the Messenger of Allaah (peace and blessings of Allaah be upon him). He took both our hands and pushed us back until we were standing behind him.
The scholars mentioned that if there is space in front of the imaam and no space behind the two people who are praying behind him, the imaam should move forward, but if there is space behind them and no space in front of the imaam, then they should move back. If there is space both in front of the imaam and behind the two people, the two people should move back and the imaam should not move forward, because he is to be followed and should not move, and because the imaam should pray with a barrier in front of him such as a wall or pillar, etc.
Imaam al-Nawawi (may Allaah have mercy on him) said in al-Majmoo’, 4/292:
“If there is an imaam and two people praying behind him, the imaam should come forward and they should stand behind him, whether they are two men or two boys or a man and a boy… Then if there is space in front of the imaam and not behind the two people praying behind him, he should move forward or they should move back. As to which is preferable, there are two opinions. The correct view is that stated by Shaykh Abu Haamid and the majority, which is that they should move back because the imaam is to be followed and should not move.
… this is if the second person joins the prayer during the qiyaam (standing). But if he comes during the tashahhud or sujood, nobody should move forward or move back until they stand up again. There is no dispute that this moving forward or back should not occur until after the second person has said the takbeer for starting the prayer, as they mentioned. And Allaah knows best.”