He invalidates his purity during tawaf (circumambulation)
If a person relieves himself during tawaf, either by passing gas, or urine, or reproductive fluid, or he touches his anus, or what resembles this, then his tawaf is broken like the prayer, then he must go and purify himself and then resume the tawaaf.
The question has some difference in opinion, but this is the correct for tawaf and the prayer, due to the saying of the Prophet ﷺ (When one of you releases air (through his anus) during Salat (prayer), he should break the Salat (prayer) then perform ablution and repeat the prayer.) narrated by Abu Dawoud, and was authenticated by Bin Khuzaymah.
Tawaf is like the prayer, but if it is broken for any reason apart from impurity, for example someone made tawaf three time, then the prayer was called, then he prayed, he returns and starts from his place, he does not need to return to the Blackstone, In fact he starts from his place and completes his tawaf. Contradicting what some of the people of knowledge have said: He must start from the black stone, and the correct is that there is no obligation for that, as the majority of the people of knowledge have said. Likewise if he attends a funeral and he prays, or someone stops to talk to him, or it is crowded, or what resembles this, then he completes his tawaf, and there is no blame on him for that.