Praise be to Allaah.
The majority of scholars are of the view that it is permissible to say salaam to the one who is praying if that will not lead to spoiling of the prayer of one who is unaware of the things that invalidate the prayer, because he may think that it is obligatory to return the salaams verbally, so he will reply and thus invalidate his prayer. The Hanafis are of the view that it is makrooh.
It says in Tabyeen al-Haqaa’iq: It is makrooh to say salaam to one who is praying, reading Qur’aan, sitting to pass judgement, researching a fiqhi matter or is relieving hismelf, and if one does say salaams to them, it is not obligatory for them to respond, because it is inappropriate. End quote.
In Sharh al-Kharashi ‘ala Mukhtasar Khaleel (a Maaliki book) (1/325) it says: It is not makrooh to say salaams to one who is praying either an obligatory or a naafil prayer. End quote.
Al-Nawawi (may Allaah have mercy on him) said in al-Majmoo’ (a Shaafa’i book) (4/105): The words of our companions suggest that it is not makrooh to say salaam to one who is praying. This is what is suggested by the saheeh ahaadeeth. End quote.
Shaykh Muhammad ibn ‘Uthaymeen said in Liqa’ al-Baab il-Maftooh (24/31): Saying salaams to one who is praying is permissible because the Prophet (peace and blessings of Allaah be upon him) did not criticize those who greeted him with salaam. But if the Muslim fears that he may confuse the worshipper, then he should not say salaams, or if he fears that he may talk and reply – i.e., because most of the common folk do not understand so if you say salaam to them they may reply Wa ‘alayka al-salaam, thus invalidating their prayer – if he knows that the prayer will be invalidated thereby. Whatever the case, we say that saying salaams to one who is praying is not wrong, because the Prophet (peace and blessings of Allaah be upon him) approved of it, unless there is the fear that the person who is greeted may be confused or his prayer may be invalidated, in which case one should not say salaams.
But how should he respond? He should not respond verbally by saying ‘Alayka al-salaam, rather he should respond by means of a gesture, by raising his hand so that the one who greeted him will know that he has returned the greeting. Then if the one who greeted him is still there when he has said the salaam and finished his prayer, he may respond verbally, but if the person has left, then the one who was greeted does not have to do anything more than what was mentioned, namely gesturing. The apparent meaning of the text is that returning the greeting is obligatory but he is excused from speaking because it invalidates the prayer. End quote.
There is nothing wrong with saying salaam to one who is praying, but if it is going to disturb the worshippers, such as saying salaam when the imam is reciting, then one should not say salaam.
And Allaah knows best.