Answered by Shaykh Rami Nsour
Question: In Morocco when there is rain usually the Maghrib and the Isha prayer are combined in the mosque. The adhan for Maghrib is called outside the mosque and right after the maghrib prayer the adhan for isha is called inside the moque and isha is prayed.
In his case he joined the prayer assuming it is maghrib but he was late and instead of joining the maghrib prayer he joined the isha prayer. So he prayed the isha prayer in congregation without having prayed maghrib.
Should he pray maghrib and isha again?
Answer: According to the Maliki school, a condition for the validity of prayer for one following an Imam, is that the follower be praying the same exact prayer as the Imam. So, a person praying Dhuhr cannot pray behind someone who is praying Asr.
One praying Dhuhr from his current day (adaa’) cannot pray behind someone making up a Dhuhr from a previous day (qadaa’). This condition is referred to as “musawatun bis salat” and is mentioned in the section of congregational prayer in the Mukhtasar or Khalil. Also according to this principle, someone praying a fard prayer cannot pray behind someone praying a nafila prayer.
In terms of the person who unintentionally prayed Maghrib behind the Imam praying Isha, the prayer of the follower would be invalid. Thus, the follower would have to repeat the Maghrib and Isha prayers.
And Allah knows best.