I walked into the mosque and a brother was in prayer. He was just getting up from his Tashahod and going into the 3rd Rakah. I stood behind him and started my Maghrib prayer in jamaa. He finished his Maghrib, and I continued my prayer. He then moved and stood behind me while I was in my 3rd Rakah of prayer, and he started his Esha prayer behind me. Is this valid? I was following the Imam of Jamaa in half my prayer and became the Imam in the second half. It seemed strange.
Yes, he may do so. It is permissible.
