If a third man comes and joins two men who are praying, then the one who is praying next to the imam should move back. However, if two women are performing congregational prayer, the third woman should join them by standing to the left of the imam.
Sheikh M. S. Al-Munajjid, a prominent Saudi Muslim lecturer and author, states: “[In the case of men praying] if a third person comes and joins two who are praying, then the one who is praying next to and slightly behind the imam should move back, because of the report narrated by Muslim from Jabir, who said: The Messenger of Allah (peace and blessings 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 Jabir ibn Sakhr came and stood on the left of the Messenger of Allah (peace and blessings 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 imam and no space behind the two people who are praying behind him, the imam should move forward, but if there is space behind them and no space in front of the imam, then they should move back. If there is space both in front of the imam and behind the two people, the two people should move back and the imam should not move forward, because he is to be followed and should not move.
Imam An-Nawawi (may Allah have mercy on him) said in his famous book Al-Majmu`: If there is an imam and two people praying behind him, the imam 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 imam and 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 most correct view is the one stated by Sheikh Abu Hamid and the majority, which is that they should move back because the imam is to be followed and should not move. This is if the third person joins the prayer during the qiyam (standing). But if he comes during the tashahhud or sujud, 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 third person has said the takbir for starting the prayer.”