Praise be to Allah
The scholars have stated that the imam’s saying the takbeer and tasleem out loud is Sunnah. In other words, it is not obligatory and is not a pillar or essential part of the prayer.
Based on that, a prayer offered behind an imam who does not say the takbeer and tasleem out loud is valid.
Ibn Qudaamah (may Allah have mercy on him) said:
It is Sunnah for the imam to say the tasmee‘ [saying “Sami‘a Allahu liman hamidah (Allah hears those who praise Him)”] out loud, just as it is Sunnah for him to say the takbeer out loud, because it is a dhikr that is prescribed when moving from an essential part of the prayer. So it is prescribed for the imam to say it out loud, as in the case of the takbeer.
End quote from al-Mughni (1/301)
Shaykh Mustafa ar-Ruhaybaani (may Allah have mercy on him) said:
It is Sunnah for the imam to say the takbeer out loud, so as to enable the people praying behind him to follow him, because the Prophet (blessings and peace of Allah be upon him) said: “When he [the imam] says takbeer, then say takbeer.” And he should say the tasmee‘ (i.e., “Sami ‘a Allahu liman hamida) and the first tasleem out loud, so that the people praying behind him may follow him. … and it is also Sunnah for him to recite out loud in a prayer in which recitation is to be done out loud, so that the imam can make those who are praying behind him hear his takbeer, tasmee‘, first tasleem and recitation in a prayer in which recitation is to be done out loud – so that they can follow him and listen to his recitation.
End quote from Mataalib Ooli an-Nuha (1/420).
If we assume that that person behind whom you prayed had not intended to lead the prayer, therefore he did not say the takbeer and tasleem out loud, the prayer offered behind him is still valid, according to the more correct scholarly opinion, because forming the intention to lead the prayer is not obligatory.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
… The fourth example is where the one who is praying behind the imam forms the intention to follow the imam, but the imam does not form the intention to lead the prayer. The prayer of the one who followed the imam when the imam did not form the intention to lead the prayer is not valid, but the prayer of the imam is valid.
For example: a man comes to someone who is praying, and follows him as if he is his imam, but that man did not intend to be an imam. The imam’s prayer is valid, but the prayer of the one who followed him is not, because he intended to follow the prayer of one who was not an imam for him. This is the view of our madhhab, as it says in al-Insaaf.
The other scholarly view concerning this issue is that it is valid for a person to follow the prayer of someone who did not intend to lead the prayer.
Those who hold this view quoted as evidence the fact that the Prophet (blessings and peace of Allah be upon him) stood up to pray one night in Ramadan, and some people gathered behind him and prayed with him, and he was not aware that they were there. Then on the second and third nights he was aware that they were there, but on the fourth night he did not come and pray, for fear that it might be made obligatory for them. This is the view of Imam Maalik, and it is more correct.
Moreover the purpose is to follow an imam, and that may be achieved in this scenario.
End quote from ash-Sharh al-Mumti‘ (2/306)
And Allah knows best.