Assalamualaikum ustaz. During my travels, I stopped by a surau to perform the jamak Maghrib and Isyak prayer. At the time it is already the time for Isyak and I intended to perform jamak ta’khir. I set the intention of Maghrib prayer and follow the imam who is performing the Isya’. In my third rakaat, should I separate from the imam or proceed to perform the final tasyahhud and wait for the imam?
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions and all those who follow his footsteps until the Last Day.
Congregational prayer is one of the eminences of Islam. A person who always performs congregational and is consistent in doing so is proof of the taqwa in his heart. This is based on the statement of Allah SWT:
وَمَن يُعَظِّمْ شَعَائِرَ اللَّهِ فَإِنَّهَا مِن تَقْوَى الْقُلُوبِ
“And whoever honors the symbols of Allah – indeed, it is from the piety of hearts.” 
Although the siyaq (context) of the verse refers to worships in hajj such as wukuf in ‘Arafah, throwing the jamrah and several other actions, however, the ibrah (wisdom) is based on the generality of the phrase. This is as stated in a famous maxim:
العِبْرَةُ بِعمُومِ اللفْظِ
“The lesson refers to the generality of the statement.”
Thus, Ibn Kathir when commenting on the verse said: “Which means (whoever honours and upholds) the commandments of Allah.” 
Moreover, Islam encourages us to always perform congregational prayer and this is the sunnah of Rasullullah PBUH and it is greatly rewarded. The Messenger PBUH said:
صَلاَةُ الْجَمَاعَةِ تَفْضُلُ صَلاَةَ الْفَذِّ بِسَبْعٍ وَعِشْرِينَ دَرَجَةً
“Prayer said in a congregation is twenty-seven degrees more excellent than prayer said by a single person.” 
Regarding the above question, in the fiqh of madhhab al-Syafie, it is permissible for the makmum to perform congregational prayer with the imam of which its nazm, which means its format, is suitable even if the number of rakaat is different such as a makmum praying Isyak following an imam performing Maghrib prayer or the consequent. If the nazm is different, then the congregation is invalid, according to the final opinion.
Imam al-Nawawi explained in his book, Raudhah al-Talibin (1/368): “If two prayers are gathered (the imam and makmum) in terms of the visible action that should be considered:
- If the total number is agreed such as Zohor prayer behind a person praying Isyak, then it is permissible to follow him;
- If the number of rakaat of the imam is less (compared to the makmum) such as a makmum praying Zohor behind an imam praying Subuh, then this is Thus, when the imam finishes his prayer, then the makmum must stand to complete his own prayer the same as the ruling for masbuq makmum. He should follow the imam in reciting qunut, however, if he mufaraqah (separate from the imam) when the imam is busy with qunut, then it is permissible.
- If the makmum is praying Zohor but the imam is performing the Maghrib prayer, when the imam sits (for the final tasyahhud) in the third rakaat, he is given a choice to follow the imam or mufaraqah from imam, akin to the ruling of qunut. 
- If the makmum’s number of rakaat is less from the imam, such as subuh prayer behind imam who is praying Zohor, then the opinion of the madhhab states is When the imam stands in the third rakaat, then the makmum has two choices;
- If he wants to, he can mufaraqah (it is not makruh) then gives salam (which means completing his prayer alone) or if he wants to wait for the imam and give salam with him. I (Imam al-Nawawi) said: wait is afdhal (prioritized). Wallahu a’lam.
- If the is an opportunity for him to recite qunut in the second rakaat, such as the imam stands briefly, it is sunnah for him to recite qunut. If he can manage, then nothing is on him.  He can also separate from the imam to recite qunut. 
- If a person wants to pray Maghrib behind an imam who is performing Zohor prayer, then when the imam stands for the fourth rakaat, the makmum cannot follow him, he should mufaraqah from the imam,  then proceed to tasyahhud and gives salam.
Thus, in answering the above question, it is obligatory for a makmum to perform Maghrib prayer behind an imam praying Isyak to do one of the two matters:
- Set the intention of mufaraqah from following imam before sitting for the final tasyahhud during the final prostration.
- Waiting for the imam in the final prostration for the makmum until the imam reaches him to sit for the final tasyahhud and gives salam together with the imam.
 According to Imam al-Khatib al-Syirbini in Mughni al-Muhtaj (1/504), means it is permissible for him to mufaraqah, if there is any warranted reason, celebrating the sunnah of Rasulullah PBUH who recited qunut. If there is any debility, it is prioritized to leave. He can also be a bit later than the imam to recite qunut without mufaraqah.
 ‘Should” here means wajib (obligatory) to mufaraqah, for if the makmum sit for tasyahhud while he is still following the imam, he has added one sit which isn’t performed by the imam. (See Hasyiah al-Jamal, 1/565 by Syeikh Sulaiman al-Jamal). Thus, he should set the intention to mufaraqah during the second prostration before sitting for the final tasyahhud if he intended to mufaraqah, and this is prioritized. If he wants to follow the imam, then he should wait in the prostration position. (See Syarh al-Muqaddimah al-Hadhramiyyah, pg. 349 by Syeikh al-Habib Sa`id Ba`isyn).