talking while offering Salah out of forgetfulness or ignorance does not invalidate Salah. Allah (Exalted be He) said:
Our Lord! Punish us not if we forget or fall into error
It is authentically reported in the Sahih of Muslim that the Prophet (peace be upon him) said:
“My Ummah (nation based on one creed) has been pardoned for what they do by mistake or forgetfully, or under duress.”
Mu‘awiyah ibn Al-Hakam Al-Sulamy (may Allah be pleased with him) is reported by
Muslim in his Sahih to have said:
“While I was offering Salah (Prayer) with the Messenger of Allah (peace be upon him), a man among people sneezed, so I said, ‘May Allah have mercy on you.’ But the people glared at me, so I said, ‘May my mother be bereaved of me, why do you stare at me?’ They began to strike their thighs with their hands, and when I saw them urging me to observe silence (I became angry), but I kept quiet. The Messenger of Allah (peace be upon him) finished the Salah, and may my father and mother be sacrificed for him, I have never seen a better teacher than him, either before or after him. I swear by Allah that he neither scolded me, nor hit me nor insulted me, but he (peace be upon him) only said, ‘Truly, nothing of people’s talk is right during this Salah; it is only Tasbih (glorification of Allah), Takbir (magnification of Allah) and recitation of Qur’an.’”
As understood from the Hadith, the Prophet (peace be upon him) did not order the man to repeat his Salah and excused him for his ignorance. (Part No. 5; Page No. 438) May Allah grant us success. May peace and blessings be upon our Prophet Muhammad, his family, and Companions.