Time is an illusion in storytelling--one that you, the author, create. You can skip millenia just by saying that they passed, and you can spend as many pages as you wish to describe a single moment, frozen in (in-universe) time. Furthermore, you can spread your material to best serve the pacing of your story: for example, consider an action scene that requires worldbuiding for the reader to be able to understand it--you can ensure you have provided that worldbuilding ahead of time, even though it was not truly important then, so that you can pace your action scene quickly, without needing to stop and explain things.
Your "rapid" change in character is a case study in this area. In what way is it rapid? Because it happens in a short amount of in-universe time? Because it happens in a fast-pased scene? You have all sorts of ways to manipulate time, so as to make this rapid change work. You will need to draw on these ways if a totally abrupt, unprepared rapid change does not work (e.g. because it is unconvincing, or feels unnatural for this character).
Examples:
1) Foreshadowing and characterisation performed before the actual "rapid change in character"
You can show that the character is strict about doing what they think is right, giving previous examples of them immediately acting upon decisions. Thus, when the character changes his mind, it feels natural that he immediately takes appropriate action, which would have seemed strange even to himself a moment before. In other words, you take the time early to establish the cadence of the character's decision making. Then the "rapid change in character" feels natural, when it happens, if only you can show that he is convinced by a moral revelation.
You can show the character never staying long in a state of not having made up his mind. When faced with a dilemma, he quickly gravitates towards one side, even if in reality the original balance was delicate. You take your time to show this, but in a previous part of the story. Now we believe in this kind of abrupt-change behaviour, because it is decisive. The character prefers to swing from one extreme to another, rather than remain undecided. We are still suprised by his change in moral choice, you still have to convice us of that, but your task is manageable.
2) Handling narrative pace for an event that is sudden in in-universe time
You can slow down and take your time to describe the character's thought-process, even if the change is abrupt in in-unverse time. You could spend 5 pages on the 2 minutes it takes him to change his mind, if that's what's needed to provide a convincing amount of detail.
Building on the previous point, you might be able to spread the material throughout a scene, in order to keep the pacing interesting. For example, we see the character is taking dangerous action to help another character in an unexpected way (but we didn't see the moment he changed his mind), and as he does so, he thinks about why he's doing it. He thinks to himself "making snap decisions--typical of me, I always thought it would get me in trouble one day", "but why am I helping this particular guy? Oh I guess because xyz...", "...", and these throughts are spread throughout the actual action of e.g. escaping a military camp, keeping an exciting pace.