If a person prays in a mosque and then goes to another one to attend a lecture or for any other reason, and finds the people there praying, then he should join them and his prayer would be considered a supererogatory (nafilah, nafl, tatawwu‘) prayer. He should do so even if it is during the prohibited times of prayer because there is a reason behind it. The evidence for this comes from what has been narrated in the hadith of Yazid bin Al-Aswad (may Allah be pleased with him) in Sunan Al-Tirmidhi in the chapter on “What has been reported about a person who prayed alone and then joins a congregation”:He said: I performed Hajj with the Prophet (peace be upon him) and prayed Fajr with him in Masjid Al-Khayf. When he completed his prayer and turned around, he found two people who did not pray with him. He said: I have to talk to them. So he came to them and they were trembling. He asked them: What prevented you two from praying with us. They said: O Prophet of Allah! We had already prayed in our places. He said: Do not do that. If you already prayed at your places and then came to a congregational mosque, pray with them too and it will become a supererogatory prayer for you.
(Sunan Al-Tirmidhi, No. 219; Sahih Al-Jami‘, No. 667)
In another hadith it is narrated that the two came after the Fajr prayer which is a prohibited time for prayer. Imam Malik has reported in Muwatta’ in the chapter on “What has been narrated about repeating the prayer with the Imam after a person has prayed individually”:Mihjan (radiAllahu ‘anhu), says that he was in the company of the Prophet (peace be upon him) and the Prophet prayed in congregation and returned while Mihjan himself did not pray with them. So the Prophet said to him: What prevented you from praying with the people? Are you not a Muslim? He said: Indeed, O Prophet of Allah! But I had already prayed at home. The Prophet said to him: When you come (to the mosque) then pray with the people even if you have prayed.