Ruling on praying whilst resisting the urge to urinate or defecate
Praise be to Allaah.
It is not permissible for a person to start praying when he is resisting the urge to urinate or defecate, because the Prophet (peace and blessings of Allaah be upon him) said: “You should not pray when food is ready or when resisting the urge to urinate or defecate.” (Narrated by Muslim in his Saheeh). The reason for that – and Allaah knows best – is that this prevents a person from having the necessary presence of mind and humility in the prayer. However, if a person prays in this state, his prayer is valid although it is somewhat lacking and is imperfect because of the hadeeth quoted; he does not have to repeat it. But if you start to pray when you are not resisting the urge to urinate or defecate, then you start to feel that need during the prayer, then the prayer is valid and there is nothing makrooh in it, so long as that need does not prevent you from completing the prayer.
And Allaah is the source of strength. May Allaah bless our Prophet Muhammad and his family and companions, and grant them peace.