Praise be to Allah.
Prayer is not valid if offered in an impure garment, if the worshipper is able to pray in a clean garment, because Allaah says (interpretation of the meaning): “And purify your garments!” [al-Mudaththir 74:4].
And because a woman came to the Prophet (blessings and peace of Allaah be upon him) and said: Menstrual blood may get onto the clothes of any one of us; what should she do with it? He said: “She should scratch it, then rub it with water, then wash it, then pray in it.” Narrated by al-Bukhaari (227) and Muslim (291). So the Prophet (blessings and peace of Allaah be upon him) commanded her to purify the garment of menstrual blood before praying in it.
If the garment becomes impure and he does not have any other garment in which to pray, one of the three following scenarios must apply:
1.He is able to wash the spot where the impurity is on the garment and pray in it, such as if the impurity is in a spot on the sleeve, for example. So he has to wash it and pray in the garment, because he is able to pray in a clean garment and he has no excuse for praying with the impurity there.
2.He can take off the garment without uncovering his ‘awrah, such as if he is wearing another garment under it that covers his ‘awrah. So he has to take off the garment and pray in the clean garment. Hence the Prophet (blessings and peace of Allaah be upon him) took off his shoe whilst he was praying, because Jibreel came to him and told him that there was some dirt on it. Narrated by Abu Dawood (650) and classed as saheeh by al-Albaani in Saheeh Abi Dawood.
3.There is no other clean garment in which he can pray, and it is not possible to wash the spot where the impurity is on the garment. The correct scholarly view is that he should pray in the impure garment, and he is excused and his prayer is valid, and he does not have to repeat the prayer after that.
Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said:
What if a person cannot find anything but an impure garment? It was said he should pray naked, or he should pray wearing it and repeat the prayer, or he should pray in it and not repeat the prayer, and this is the most correct of the scholarly views, because Allaah did not command His slave to offer the obligatory prayer twice, unless he did not do the obligatory action that he was able to do the first time, such as if he prays without taking his time; then he has to repeat the prayer, as the Prophet (blessings and peace of Allaah be upon him) ordered the man who prayed without taking his time to repeat the prayer, and he said, “Go back and pray, for you have not prayed.” Similarly, if a person forgets to purify himself and prays without wudoo’, he has to repeat the prayer, as the Prophet (blessings and peace of Allaah be upon him) commanded the man who did wudoo’ and forgot a spot on his foot which the water did not touch to repeat his wudoo’ and his prayer. As for the one who did what he was commanded to, to the best of his ability, Allaah says (interpretation of the meaning): “So keep your duty to Allaah and fear Him as much as you can”[al-Taghaabun 64:16], and the Prophet (blessings and peace of Allaah be upon him) said: “ If I command you to do something, do as much of it as you can.” End quote.
Majmoo’ al-Fataawa, 22/34, 35
And Allaah knows best.