Please contribute generously in order to ensure the continuity of our website InshaAllah.
Praise be to Allah.
Firstly:
Saying “Sami‘a Allahu liman hamidah” when rising from bowing is one of the obligatory parts of prayer according to the correct opinion. For more details, please see the answer to questions no. 65847 and 90094.
Secondly:
Once this is understood, if a person omits one of the obligatory parts of the prayer – which includes saying “Sami‘a Allahu liman hamidah” – his prayer is not rendered invalid unless he did that deliberately. If he omitted it because he forgot or was ignorant of the ruling, then his prayer, and the prayer of those who prayed behind him, is valid. But he has to do the prostration of forgetfulness (sujood as-sahw) when he remembers it or learns of the ruling, if not much time has passed. If a long time has passed, he does not have to do it, because the time for it has gone.
It says in Daqaa’iq Ooli an-Nuha (1/219): Whoever omits an obligatory part (of the prayer) because he is ignorant of the ruling, in the sense that it never crossed his mind that a scholar would say it was obligatory, is like the one who forgot or made a mistake. So he should do the prostration of forgetfulness if he learns of that before the time ends, otherwise there is no need, and his prayer is still valid. End quote.
Shaykh ‘Abd al-‘Azeez (may Allah have mercy on him) was asked:
What should the imam or person who prayed behind him do if he says “Allahu akbar” instead of “Sami‘a Allahu liman hamidah” or vice versa?
He replied:
It is not permissible for him to do that deliberately; rather what the worshipper must do is pray as the Prophet (blessings and peace of Allah be upon him) did. So he should say “Allahu akbar” when appropriate and “Sami‘a Allahu liman hamidah” when appropriate, and “Rabbana wa laka al-hamd (Our Lord to You be praise)” when appropriate. Whoever does something other than that by mistake, there is no sin on him, but he should do the prostration of forgetfulness, if he was leading the prayer or praying on his own.
End quote from Majmoo‘ al-Fataawa (29/286)
Thirdly:
There is no blame on you for having said both “Sami‘a Allahu liman hamidah” and “Rabbana wa laka al-hamd.” The Shaafa‘is stated that it is mustahabb, i.e., it is mustahabb for the one who is praying behind an imam to say both “Sami‘a Allahu liman hamidah” and “Rabbana wa laka al-hamd,” although the more correct scholarly view is that the one who is praying behind an imam should say only “Rabbana wa laka al-hamd.” We have discussed the difference of scholarly opinion previously, in the answer to question no. 43574
To sum up: The prayer of your imam is valid, because he did not deliberately omit to say “Sami‘a Allahu liman hamidah” and “Rabbana wa laka al-hamd.” Rather he omitted it because of his ignorance. May Allah reward you with good for alerting him to that.
And Allah knows best.