The gemara says that gravediggers who worked on yom tov were at first invalidated as witnesses by Rav Papa, but Rav Huna Brei D'rav Yehoshua was machshir them because "they think that they are doing a mitzvah". This din is paskened in Shulchan Aruch 34:4, that anyone who violates even an issur torah but justifies it by thinking that they are doing a mitzvah, wouldn't become passul l'eidus. The gemara then asks and answers: והא קא משמתינא להו? סברי כפרה קא עבדי לן רבנן. According to Rashi the question is: We put them in cheirem and they violate the same prohibition a second time so they can't justify that they are doing a mitzvah? To this the gemara answers: Even though we put them in cheirem they still convince themselves that they are doing a mitzvah, just that they think that the cheirem is necessary for atonement of being mechalel yom tov. Rashi seems to explain the justification of the gravediggers to be similar to one who fasts a ta'anis for a dream no shabbos who is doing the right thing, yet needs to fast again for atonement for fasting on shabbos. Here too, they think that they are doing the right thing by burying the dead on yom tov, just that they require the cheirem to serve as a kappara for their actions.
The Ran seems to have a different approach in this question and answer. The Ran seems to understand that if they were to repeat the aveira again after being put in cheirem, they would certainly become passul because they should understand from the cheirem that they did an aveira. The question of the gemara is that since we put them in cheirem and they don't bother coming to beis din to justify their actions, we should assume that they are intentional violators and passul for eidus? To this the gemara answers that the reason that they don't come to justify is because as soon as they are put in cheirem they realize that they did an aveira and want the punishment of cheirem to serve as an atonement.
We are left with a machlokes between Rashi and the Ran if they would bury someone a second time after being put in cheirem, whether they would be passul. But, all agree that the justification of מצוה קא עבידנא, is not just a rationale to make them kasher m'doraysa, but would even make them kasher m'drabonon. Why is this different than all those who are listed in the mishna 24b who become passul m'drabonon even though they can justify their actions such as a gambler where tosafos writes that even according to the opinion that they violate theft m'doraysa, they are only passul m'drabonon because they don't realize the severity of their actions? Also one who lends with interest and violates an issur d'oraysa, Tosafos writes would only be passul m'drobonon since he justifies taking the money with the consent of the borrower? The answer seems to be that when they justify their actions by saying that they are doing a mitzvah then they aren't even passul m'drabonon, but if they merely justify by not realizing the severity of the issur then they would still be passul m'drabonon. However, this wouldn't explain סוחרי שביעית where Tosafos says that even if they violate an issur d'oraysa they would only be passul m'drabonon since they consider themselves to be providing livelihood to the poor in the shemittah year. Clearly, they justify by saying that they are doing a mitzvah, yet they are passul m'drabonon, so why are the gravediggers not even passul m'drabonon? I would suggest that there is a distinction between the gravediggers who think that the act of burying is a mitzvah, and those who do business with fruits of shevi'is, who know that making money with the fruits of shevi'is isn't a mitzvah, but think that the benefit of the mitzvah of providing parnasah to the poor would offset the aveira. When they think that their action is a mitzvah, they aren't even passul m'drabonon, but when they just think that their aveira is offset by a mitzvah, they are still passul m'drabonon.