All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
This act is permissible and it is a recommended act. The person who is going to pray the obligatory prayer is the person who should lead the prayer and not the person who prays it as an optional prayer. This is because there is a difference of opinion among the scholars, and some of them forbade a person who prays an optional prayer to lead a person who prays an obligatory prayer.
The least number by which the congregation is fulfilled is two people. So if one person prays with another one, then it considered for him as having prayed with the congregation.
This is permissible in all the five obligatory prayers according to the correct view (of the scholars) because praying a prayer for a reason at the times of prohibition is permissible as per the Shaafi'i School, and this is the view we adopt here in Islamweb.
In any case, a person should be keen on going early to the mosque so that he would catch up with the prayer in congregation with the Imam.
Allah Knows best.