Praise be to Allaah.
There is nothing wrong with that according to the more correct of the two scholarly opinions. There is a difference of opinion on the matter, but the correct view is that it is permitted, because the Prophet (peace and blessings of Allaah be upon him) stood to pray on his own one night, and Ibn ‘Abbaas came and prayed with him. In this case, the Messenger (peace and blessings of Allaah be upon him) became the imaam and Ibn ‘Abbaas became the one who was following him in prayer. So the intention of the Prophet (peace and blessings of Allaah be upon him) changed from the intention to pray alone to the intention to lead the prayer. This indicates that it is permissible. This applies equally to naafil prayers and to fard prayers, except in cases where the evidence specifies something to the contrary. This view is more correct than the other view, and it is also the view favoured by Shaykh al-Islam Ibn Taymiyah. It was also narrated from Imaam Ahmad. This is the more correct view, in sha Allaah.