It is the verdict of all marja’s and mujtahids that it is mustahabb to recite salawat when hearing the blessed name of the prophet (pbuh), and this verdict also covers when one is in prayer as well.
Imam Khomeini says: “Whenever one hears/says one of the names of the prophet (pbuh) such as ‘Muhammad’ or ‘Ahmad’, or one of his titles or surname such as ‘Mustafa’ or ‘Abul-Qasem’, it is mustahabb to recite a salawat.”
Ayatullah Makarem Shirazi says: “Sending blessings and salawat upon the prophet (pbuh) and his household after prayer or in prayer and in other states is very mustahabb; [so] whenever one hears the blessed name of he prophet (pbuh) or his title or surname, let it be ‘Ahmad’, ‘Muhammad’, ‘Mustafa’ or ‘Abul-Qasem’, he should recite a salawat, even while praying.”
It should be noted that it can be inferred from what these and other scholars have said (regarding the being mustahabb of salawat whenever and wherever) that if the prophet’s (pbuh) name or the ‘verse of salawat’ (verse 56 of surah Ahzab) is repeated, the istihbab (being mustahabb) will also be repeated, making it mustahabb to repeat the salawat the number of times the prophet’s (pbuh) name has been repeated. Of course, if one is praying, he can only repeat the salawat a number of times that will not take him out of the state of prayer and make him look like he isn't praying anymore (because one of the things that makes one’s prayer void, is to do something that contradicts the state of prayer, like jumping up and down; one who jumps up and down doesn’t seem to be praying anymore; the same goes for reciting the salawat a number of times that may contradict the state of prayer, of course, it is the one praying who has to recognize if what he does actually contradicts his praying state or not).
Concerning the ‘verse of salawat’, Imam Ali (as) says: “When you read the verse of “ان الله و ملائکته یصلون علی النبی...”, send salawats upon the prophet (pbuh) much.”