Ruling      on praying behind someone who is praying alone
Question

If a Muslim starts to pray on his own, then another person comes along, is it OK for him to join the first person in his prayer, or should he keep away from him because he started his prayer alone?
Praise be to Allah.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 Allah 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 Allah 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 Allah 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 Allah.