I entered the mosque one day and there was water in my house to do wudoo’ for prayer, but I still had my wudoo’. However the need to relieve myself was pressing and I could not find any water, and I was afraid that I would miss the prayer in congregation, so I joined the prayer.
Praise be to Allaah.
It is makrooh for the worshipper to start praying when he is suppressing the need to defecate or urinate, because the Prophet (blessings and peace of Allah be upon him) forbade doing that, because of what it results in of failing to attain complete focus and contemplation in prayer.
See the answer to question no. 8603
If the worshipper is suppressing the need to urinate or defecate and he cannot find any water with which to do wudoo’, it is better for him to relieve himself then do tayammum and pray.
His praying with tayammum whilst having proper presence of mind and focus is better than praying after doing wudoo’ with water but without proper focus, because the heart and essence of the prayer is proper focus (khushoo‘), so it is essential to maintain it.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) was asked: Which is better: praying with wudoo’ whilst suppressing the need to relieve oneself or to relieve oneself then do tayammum due to lack of water?
Praying with tayammum without suppressing the need to relieve oneself is better than praying with wudoo’ whilst suppressing the need to relieve oneself, because praying when suppressing the need to relieve oneself is makrooh and is not allowed, and there are two opinions concerning its validity. But praying with tayammum is valid and there is nothing makrooh in it, according to scholarly consensus.
End quote from Majmoo‘ al-Fataawa, 21/473
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: If someone were to ask: A man has wudoo’ but is suppressing the need to urinate or pass wind, but if he does so he does not have any water with which to do wudoo’. Should we tell him to relieve himself and do tayammum for prayer, or should we tell him to pray whilst suppressing the need to urinate or pass wind?
The answer was:
You should tell him to relieve himself and do tayammum; he should not pray whilst suppressing the need to urinate or pass wind. That is because praying with tayammum is not makrooh, according to scholarly consensus, but praying whilst suppressing the need to urinate or pass wind is not allowed and is makrooh. And some of the scholars regarded it as haraam and said: Prayer whilst suppressing the need to urinate or pass wind is not valid, because the Messenger (blessings and peace of Allah be upon him) said: “There is no prayer in the presence of food or when suppressing the need to urinate or defecate.” End quote from ash-Sharh al-Mumti‘, 3/236
So the prayer that you offered is valid, in sha Allah, and you do not have to repeat it.
And Allah knows best.