Assalamualaikum ustaz. Is it necessary to repeat or replace certain worship that has been performed with confidence but later he found that it was wrong?
Alhamdulillah, praise and gratitude to Allah SWT for His countless blessings for us all. Praise and salutations to our beloved Prophet Muhammad PBUH, his family, companions and all those who follow his footsteps until the Last Day.
This matter depends on the situation, for instance, in the issue of facing the qibla, Imam al-Nawawi explained: “Whoever prayed with an assured ijtihad but then he realized that it was wrong, he should qadha’ (replace) it according to the apparent opinion, even if he was certain (later he learned that it was wrong), it is obligatory for him to perform it again (qadha’).” 
Another example is when a person sees najis on his body after prayer; Imam al-Nawawi said: “In our madhhab (al-Syafie), it is stated that removing najis is one of the valid conditions of prayer, thus, if a person is aware of this, then his prayer is invalid without khilaf. Even if it is because he has forgotten or is ignorant, the madhhab states his prayer is still invalid.” 
Although supposedly, he only realized this after he has prayed after some time, then he sees there is some lizard dropping on his foot, he can assume that it happens after he has prayed and not while he is praying.