Praise be to Allah.
At-Tirmidhi (241) narrated that Anas ibn Maalik (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “Whoever prays to Allah for forty days in congregation, catching up with the first takbeer, he will be recorded as being free from two things: free from the Fire and free from hypocrisy.” This hadith was classed as da‘eef by at-Tirmidhi and a number of earlier scholars; they stated that the problem with it is that it is mursal. However, some later scholars classed it as hasan, including al-Albaani in Saheeh at-Tirmidhi.
See: Talkhees al-Habeer (2/27).
If the people in the mosque put two prayers together, that does not rule out a worshipper’s having caught up with the first takbeer. That applies whether the worshipper is leading the prayer as an imam or is praying behind an imam and made a mistake in his prayer. The bounty of Allah, may He be exalted, is immense and His generosity knows no bounds.
We ask Allah, may He be exalted, to help us and you to do more righteous deeds and acts of worship.
And Allah knows best.