The evidence for this is that the Prophet ﷺ would stand in front of the people, and he said, “Pray as you have seen me praying.” (1) This encompasses the prayer in its actions, number of units, manner, and all its conditions, including where one stands. Thus, standing in front of him is contrary to the sunnah, and in that case the prayer is invalid.
Some scholars held that the prayer is not invalid, because it has not been reported that the Prophet ﷺ forbade praying in front of the imam. At most, this was his practice. Jabir ibn Abdullah and Jabbar ibn Sakhr stood with him, one on his right and the other on his left, whereupon he took them and moved them behind him. (2) Since the only evidence for this is his action, it is recommended rather than obligatory. This was also the view of Imam Malik, may Allah have mercy on him.
Shaykh al-Islam Ibn Taymiyyah, may Allah have mercy on him, adopted a middle position. He said: if necessity requires it, then the prayer of a follower standing in front of the imam is valid; otherwise, it is not.
Necessity may require this on Fridays, or during the days of Hajj in ordinary mosques, when the marketplaces become crowded and people pray in front of the imam.
This view occupies a middle ground between the two opinions, and the middle view is often the stronger one, because it takes account of the evidence cited by both sides.
If someone were to say: the evidence here is based on an action, and the principle is that evidence based on an action does not indicate obligation?