Assalaamu alaykum wa rahmatullaah. I joined a congregational pray to pray the Maghrib, which is a three-unit prayer; unfortunately, they were praying the ‘Ishaa’; I caught their last two units of prayer. What can I do?
All perfect praise be to Allah, the Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
What you should do is stand up for the third unit of prayer of the Maghrib after the imam concludes the prayer with the Salaam greeting, and then you recite Surat Al-Faatihah only and silently, or you recite Al-Faatihah and a surah audibly, but not in a way that it disturbs the praying people. One can do either of these, and it is a flexible matter – Allah willing.
The Hanbali book of Fiqh Kash-shaaf Al-Qinaa’ reads, "The person preceded in prayer has the choice, when he makes up for what he missed of prayers that are said out loud other than the Friday prayer; he has the choice to recite them [i.e. the units that are recited loudly] loudly or silently, with the exception of the Friday prayer [which he has to recite loudly – in case he missed one unit of prayer, for example] after the imam concludes the prayer."
Then you recite the last Tashahhud completely and then you say the Salaam (to conclude the prayer).
This is what you should do, and your prayer will be valid, Allah willing.
The scholars stated that it is permissible for someone who missed the Maghrib prayer or other prayers to pray them with a congregation that is praying the ‘Ishaa’ prayer or any other prayer – according to the preponderant opinion of the scholars in this regard. This is what is known among them as ‘the difference between the intention of the imam and that of the one praying behind him.’
Imam An-Nawawi said:
"It is valid to pray the supererogatory prayer behind someone who is praying the obligatory prayer and vice versa, and it is valid to pray the obligatory prayer behind someone who is praying another obligatory prayer that corresponds to it in the number of units of prayer, such as praying the Thuhr behind someone who is praying the ‘Asr; and it is valid (correct) to pray an obligatory prayer behind someone who prays an obligatory prayer that is shorter than it; all of this is permissible, and there is no difference of opinion about that in our School (of Thought)."
Allah knows best.
You can search for fatwa through many choices