All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
Whoever prays and then becomes certain after the expiry of the time of the prayer that he was not in a state of purity, then he is obligated to repeat the prayer as his prayer is not valid because the Prophet said: “Allaah does not accept the prayer of any one of you if his ablution is invalidated until he performs ablution again.” [Al-Bukhari]
Similarly, if someone thought that he was standing within the boundaries of the Mount of ‘Arafah and then it becomes clear to him after the expiry of the time of standing at it (i.e. after the beginning of Fajr of the 10th of Thul-Hijjah) that he was standing outside the boundaries of the Mount of ‘Arafah, then his Hajj is void as he missed one of the pillars of Hajj which is the standing at the Mount of ‘Arafah. Therefore, he should come out of the rituals of Hajj by performing ‘Umrah and offer a sacrifice and then he should make up the Hajj the next year.
Likewise, if someone believed that he had performed seven rounds of Tawaaf and then he becomes certain that he had performed less than seven rounds, he is obligated to go back and perform Tawaaf seven rounds if there was a long interval between the two Tawaafs, and if the time is short according to the custom, then he may complete the remaining rounds only.
Hence, it becomes clear that whoever leaves one of the pillars of an act of worship or one of its conditions while being able to perform it, his act of worship is not valid even if he believed that he had done it as long as he becomes certain afterwards that he did not perform it.
Allaah Knows best.