The Messenger of Allah ﷺ said, "When the imam says, 'Allah hears whoever praises Him,' say, 'O Allah, our Lord, to You belongs all praise.' Whoever's words coincide with the words of the angels will have his past sins forgiven."
أن رسول الله ﷺ قال: إذا قال الإمام سمع الله لمن حمده، فقولوا: اللهم ربنا لك الحمد، فإنه من وافق قوله قول الملائكة، غفر له ما تقدم من ذنبه.
Malik narrated it in "Prayer" (47) from Sumayy, freedman of Abu Bakr, from Abu Salih Samman, from Abu Hurairah, mentioning the hadith, and Bukhari narrated it through his route in "Adhan" (796), and Muslim in "Prayer" (409), saying, from Suhayl, from his father, from Abu Hurairah, from the Prophet ﷺ, with the meaning of Sumayy's hadith.It appears that Malik, may Allah have mercy on him, used to narrate two hadiths with this chain, the hadith about saying "Ameen" as mentioned previously, and the hadith about saying "sami Allahu liman hamidah" and "rabbana wa laka al-hamd." Bukhari recorded both hadiths in their respective places, while Muslim recorded only the hadith about saying "sami Allahu liman hamidah" and "rabbana wa laka al-hamd."As for Muslim's statement, from Suhayl, from his father, from Abu Hurairah, from the Prophet ﷺ, with the meaning of Sumayy's hadith, this is not about saying "sami Allahu liman hamidah" and "rabbana wa laka al-hamd," but rather about saying "Ameen," as he himself narrated it, saying, Qutayba bin Saeed told us, Yaqub (meaning Ibn Abdul-Rahman) told us, from Suhayl, from his father, from Abu Hurairah, that the Messenger of Allah ﷺ said, "When the reciter says, 'not of those who have earned Your anger, nor of those who have gone astray,' and those behind him say Ameen, and his saying coincides with the saying of the people of heaven, his previous sins are forgiven" (76/410).Abdul-Razzaq narrated it (2912), and through his route Nasai (1060), from Mamar, from Zuhri, from Abu Salama bin Abdul-Rahman, from Abu Hurairah, who said, when the Messenger of Allah ﷺ raised his head from the ruku, he would say, "O Allah, our Lord, to You belongs all praise."