Second: Must the imam’s prayer and the follower’s prayer belong to the same legal category? In other words, may one pray an obligatory prayer behind someone who is performing a supererogatory prayer, or vice-versa—may one offer a supererogatory prayer behind someone who is leading an obligatory one? Let us examine the issue.
If a person prays a supererogatory prayer behind an imam who is praying an obligatory prayer, there is no problem with that, for the Sunnah establishes its permissibility. The Messenger of Allah ﷺ once turned from the dawn prayer in Masjid al-Khayf at Mina and found two men who had not prayed. He asked, “What kept you from praying with the congregation?” They said, “Messenger of Allah, we already prayed in our quarters.” (It is possible that they did so because they thought they would miss the congregational prayer, or for some other reason.) He replied, “When you have prayed in your quarters and then come to a mosque where a congregation is being held, pray with them as well, for it will be a voluntary prayer for you.” “It” here refers to the second prayer, for the first has already fulfilled the obligation and discharged the duty.
Accordingly, when the follower is performing a voluntary prayer while the imam is performing an obligatory one, there is no objection, as this hadith demonstrates.