بسم الله الرحمن الرحيم
This short series of articles will research some of the issues relating to the prayer. It will be organised in a question and answer style with all information referenced to the fatawaa of the scholars.
Q: A person enters the masjid for ‘Isha prayer, then he remembers he has not yet prayed Maghrib so what does he do?
A: If you enter the masjid and the ‘Isha prayer is about to be established [i.e. iqaama has been called and it is beginning] but then you remembered you have not prayed Maghrib, in that case you enter with the ‘Isha congregation with the intention of Maghrib. The first three raka’aat are prayed as normal, but when the Imaam stands up after the third rak’at to start the fourth rak’at, you stay sitting and wait for the Imaam and rest of congregation to complete their fourth and then give the salam [tasleem] with the Imaam together at the end.
Similarly though, you can stay sitting after the third and finish the prayer and give the salam by yourself, then rise up and join the Imaam and congregation in what is left of the ‘Isha prayer [i.e. join them in their final rak’at of ‘Isha and then continue after they finish].
It is of no harm that the intentions are different between yourself and the Imaam in accordance to the correct opinion of the scholars on that.
[Based on Fatawa Arkaan ul-Islaam of Shaikh ibn ul-Uthaymeen, p290]