In reference to the incident which you experienced, we must first look at the principals of forming lines in congregational prayer from a fiqhi point of view:
- The person following in prayer should not be ahead of the person leading the prayer (the Imam).[1]
- It is Mustahab (merited) that if there is one person following the prayer and he is male, that he stand on the right side of the Imam[2] and based on obligatory precaution he should stand just slightly further behind the Imam, and if there are several persons following the prayer then they should form a line behind the Imam.[3]
So apparently in this case, both of the individuals following the prayer were trying to do their Islamic duties. However in reply to the question as to whether or not the action of the Second Ma'moom (person following the prayer) which caused the movement of the first Ma'moom, is grounds for the invalidation of the first Ma'moom's prayer; the following must be said:
Scholars say: Any action which disrupts the structure of prayer will invalidate the prayer, such as; clapping, jumping up and down, etc.[4]
The Late Sayyid Muhammad Kazem Tabataba'ee Yazdi states[5]:
There is no harm in walking two, three or more steps during salat in such a way that the direction of the qibla is correctly maintained[6], for the reason that this amount is not regarded as 'excess movement’. However, the criterion is not '‘excess’' rather it is, "the disrupting of prayer structure", and with this amount or even possibly more the structure of prayer is not disrupted. So taking that into consideration, there are also hadith which express the permissibility of this issue.[7]
So in congregational prayer there is nothing wrong with slight movement in order to make the line neat or to make room for someone else to pray.
Grand Ayatollah Makarem Shirazi's response to this question:
There is nothing wrong with this act in itself, so long as when the Ma’moom moves slightly backwards the Imam is not in the state of reciting any dhikr.
[1] Some scholars have prohibited standing parallel. - Catechism of Legal Authorities, Vol.1, Pg.781 & 782 Ques.1432
[2] Some scholars have elaborated on this merited act in their catechism - Catechism of Legal Authorities, Vol.1
[3]Catechism of Legal Authorities- Section: Alwasilah Ila Nilul Fazilah, Pg.107; Jameh Abbasi and it’s Completion (Mahshi), Vol.1, Pg.96
[4]Catechism of Legal Authorities, Vol.1, Pg.628 Ques.1151
[5]Sayyid Muhammad Kazem Tabataba'ee Yazdi, Questions and Answers, Pg.47 (Jame’ul Fiqh Software)
[6]Standing in face of the qibla
[7]Wasa’il Ul-Shia, Vol.4, Pg.1279, Narration 1 & Vol.5, Pg.443, Section 43, Congregated Prayer; Man La Yahzer, Vol.1, Pg.277, Narration 851 & Vol.1 Pg.494, Narration 1421; Al-Kafi, Vol.3, Pg.272, 316 & 385; Tahzibul Ahkam, vol.3, Pg.275, Narration 119