Phlegm is taahir (pure), because of the report narrated by al-Bukhaari (409) and Muslim (550), from Abu Hurayrah (may Allah be pleased with him), according to which the Messenger of Allah (blessings and peace of Allah be upon him) saw some sputum in the qiblah of the mosque. He turned to the people and said: “What is the matter with one of you who stands before his Lord and spits in front of him? Would any one of you like to have someone stand before him and spit in his face? If one of you must spit, then let him spit to his left, beneath his foot. If he cannot do that, then let him do like this,” and al-Qaasim -- one of the narrators of the hadeeth -- described how he spat into his garment then rubbed part of it against another part.
Ibn Qudaamah (may Allah have mercy on him) said:
If it was najis (impure), he would not have told him to rub it with his garment during prayer or to put it beneath his foot. It makes no difference whether the phlegm comes from the head or the chest. He also said:
Phlegm is one of the two types of sputum and is similar to the other. If it was najis, the mouth would be made impure by it, … and there is no report from the Sahaabah (may Allah be pleased with them) to that effect, even though it is a common problem. End quote.
Swallowing phlegm during prayer does not come under the same ruling as food and drink, because it is not food or drink.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) was asked:
The fuqaha’ said that sputum invalidates the fast of a fasting person. Is it possible to draw an analogy with prayer, i.e., does sputum invalidate the prayer?
The fuqaha’ are not unanimously agreed on this. Rather the madhhab of Imam Ahmad has two opinions as to whether it breaks the fast or not.
What is meant by the kind of sputum that breaks the fast is that which reaches the mouth. As for that which appears in the throat and goes down into the chest, that does not break the fast. I do not think the sputum reaches the mouth of anyone and is then swallowed, because it is off-putting. But whatever the case, most of the Hanbali fuqaha’ say that if sputum reaches the mouth and is then swallowed, it invalidates the fast.
With regard to the analogy of that, that if that happens during prayer, it invalidates the prayer, if we say that this is like food. But I have not come across anyone discussing this issue with regard to prayer. Moreover the idea that it breaks the fast if it reaches the mouth then is swallowed is subject to further discussion, because this is not regarded as eating or drinking. It did not enter his body from outside, rather it is still inside him, and the mouth is regarded as part of the outside, not part of the inside. End quote.
Liqa’ al-Baab al-Maftooh, 116/17
As phlegm is taahir and is not food or drink, and does not come under the same rulings as food and drink, if a person swallows whilst praying, his prayer remains valid, especially if he could not help it and was not able to spit it out into a handkerchief and the like. Swallowing phlegm is usually of-putting, and what is prescribed is to spit it out into a handkerchief and the like, not swallow it.
And Allah knows best.