All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
It is valid for a Muslim who is offering an obligatory prayer to pray behind another who is offering a voluntary one. This opinion is adopted by some scholars including the Shaafi‘i scholars . It is also the preponderant opinion, based on the Hadeeth on the authority of Mu‘ath where it was stated that he used to offer the prayer with the Prophet, sallallaahu ‘alayhi wa sallam, then return to his people, and lead them in the same prayer. [Al-Bukhari and Muslim]
Hence, it is valid for someone to offer the obligatory Maghrib prayer behind someone who is praying the voluntary Maghrib prayer. However, one who is praying the voluntary prayer must not add to the number of its Rak‘ahs, he should rather end it according to what he had intended it to be. If he adds to the number of Rak‘ahs he had first intended, the one praying behind him is not permitted to follow him in the added Rak‘ahs, as long as he knows that they are additional, and if he did, his prayer is invalid and he has to offer it again. If the one led in prayer is not aware whether the Imaam's prayer is the Maghrib Sunnah prayer, a second offering of the obligatory Maghrib prayer, or a voluntary prayer, then he may follow him since he is not aware of the addition that invalidates the prayer.
Allaah Knows best.