Much of the self-righteous character depends on the landing. You can have them be a jerk for the entire story and then redeem them with a good ending. I don’t mean good as in happy, but a well-written one. There are various ways to go here, but it all depends on the build-up and author. So, I’m only going to present a general overview of possibilities:
Stays the Same
Let’s get the highest risk one out of the way. It’s entirely possible that the self-righteous character goes through the entire adventure only to retain their beliefs. This is possible if their beliefs are solid or something happens to make them think they are always on the right path. Unfortunately, the arrogance and chance of them irritating the reader makes this ending a major challenge. Nobody wants the jerk to remain a jerk, so you would need to evolve them in another way. Maybe they’ve attained a position where this trait is a benefit or they simply walk away from all of the other survivors. You could also have them meet someone who is just as bad and they marry. There needs to be a life change of some type that is big enough to overshadow or explain the retention of self-righteousness.
Death by Sacrifice
This is a way to have them go out with some nobility. Their beliefs can drive them to die and help the others get ahead in the story. You would have to establish that this is a possibility early on though. It could also be that they are happy to have friends who keep them around even if they don’t agree. So, they sacrifice themselves out of friendship regardless of their beliefs. You may need to have them acknowledge their own annoying habits and how they never felt accepted until now. It can be done for the whole group or a single character too.
Death by Betrayal/Allies
Not the best way to go because it turns the story dark and will stain all of those who are involved. Any heroes who turn on the self-righteous character for no reason other than being fed up with their attitude will be seen differently. This is more for villains than heroes. Even in comedy, it will leave a sour taste in the mouths of your readers and, quite possibly, yourself.
Another self-explanatory fate where the character comes out even more judgmental than before. Something happened in the finale that made them more confident about their superiority. This doesn’t mean they turn evil or lose their friends. It’s simply that they are even harder to deal with. Since the story is over, you don’t have to worry about showing more than a little of this in a final scene. For example, you can have them telling a crowd of people about their role in the adventure and how their beliefs helped them through everything. It can be exaggerated and peppered with slights at the others, who may ignore the antics. This comes alongside a desire for attention and fame, which the other heroes might not be interested in.
Loss of Beliefs
On the opposite side of the spectrum, the self-righteous character can be struck by an event that shatters their world view. This is a vicious method of evolution that is fairly common because authors love burning the pompous down and forcing them to grow from the ashes. It starts with an event that they cannot deny goes against whatever they believe and then they are left wondering about their path. Inevitably, they restructure their way of thinking. It can be done through them leaving and coming back after some self-reflection or the readers see the turmoil acted out. Depression, anxiety, anger, and a host of other negative reactions come into play because this is the equivalent of spiritual grieving. It’s not always a positive too. They can come out darker or weaker than before if they decide that nothing matters.
Yeah, this happens a lot. The self-righteous hero is tempted to the other side by a villain who makes them think they agree on things. It can be a subtle twisting of their own beliefs that draws them to the other side or maybe a revelation that the other heroes don’t take them seriously. Either way, the character commits a betrayal and jumps. It can be reversed down the road if they realize they made a mistake. Something to keep in mind is that they rarely become the main villain. Typically, the self-righteous character takes on the role of henchman or sidekick. If they become the central antagonist, it means the original one has been removed. That makes redemption even more difficult because you need them to stay there until the end or a replacement appears.