Yes and no.
Does there need to be some justification for the characters behavior, or an explanation why they did it even though there was no justification? Sure. Otherwise if feels too random.
As an oversimplified example: Your hero walks through a busy marketplace. Without any buildup whatsoever, he suddenly and inexplicably stabs a bystander to death, and then just continues their day as if nothing happening.
You can't leave that hanging in the air, there needs to be some sort of explanation as to why this was considered the right course of action, or why this course of action was taken anyway.
This is a matter of Chekhov's gun. It needs to have some relevance to the story, because otherwise it is a pointless distraction.
However, it does not logically follow that a character is able to eloquently explain precisely why they chose to act the way they did. It depends on whether it was a conscious choice, and whether they're able to verbalize their thought process.
As an oversimplified example, maybe your hero spared one of the henchmen (after already killing several others) because she really resembles a loved one. He didn't actively think "oh this henchmen looks like Cindy, I should not kill her then", because that would be way too self-aware to be realistic. But he may have subconsciously become more self-aware about the henchman being a human being, which in turn led him to not kill them.
The issue is that if you explain, you're essentially telling and not showing, so I am wondering how to do it properly.
Some thought processes would be naturally verbalized when communicating with other characters), e.g. if the hero will obviously be asked by his sidekick (who was present at the time) why he stabbed that bystander in the marketplace. Having this come from a conversation right after the event isn't bad writing, it's actually a very realistic conversation.
Furthermore, when dealing with trains of thought, which lie at the basis of behaving a certain way; there can be value to showing the internal train of thought, but there can also be value to not showing it and instead having to rely on what the characters claims to be their train of thought.
For example, there is a reason why your everyday whodunit tends to focus on what the suspects say and claim, not what their unfiltered genuine thoughts are.
and instead of outlawing slavery and punishing slavers of that ethnicity, he rewards them to increase political power when he doesn't need more political power, what would you do in that situation?
Does this need justification? Yes. This is similar to the market stabbing I used as an example.
However, that doesn't mean that it needs to be said. It can be reflected in other ways, but it very much depends on what the actual underlying reason is. In other words, it very much depends on the story you're telling.
- If the former slave is playing some high level chess game where this actions seems to contradict their main motivation, but is actually a clever move that causes some known butterfly effect, then:
- If it will retroactively be clear that this is the case when that butterfly effect comes to fruition, you can leave it up to the reader to understand.
- If it won't be obvious even when the butterfly effect comes to fruition, it may be more realistic to only have that explaining conversation afterwards.
- If it is plausible that [sidekick] would obviously have pulled this character aside the moment their weird behavior happened (well before the butterfly effect would come to fruition); you're going to have to privately reveal it to that sidekick, but not necessarily the reader. It depends on whether you want your reader to be aware of the ploy or not.
- If the overall story is one about a fall from grace, the "bad" decision is actually exactly what it looks like. You don't have to explain it when it in and of itself serves as an example of how this person's character is changing.
- This is very common for villain origin stories, where the character at one point will do the opposite of what they used to do, which signals that their moral compass has turned.
- If the overall reason is some PTSD-like instinctive behavior to "reward the masters"; this is something that can be telegraphed in several (minor) cases, eventually leading up to and culminating in the character being conflicted when both the severity of the "bad" behavior and the need to "rewards the masters" are both very high. This doesn't require active explanation, because it is already exposed through a chain of occurrences that this character will obviously be faced with in their life.
To really sum it up, when the reason for this unusual behavior would inherently show itself repeatedly during the character's life (even if only at specific times), it is better to show those occurrences (or indirectly reveal their existence).
If the reason for the unusual behavior is a willful but intentionally obfuscated choice; then you can either let the reader retroactively work it out once the consequence of that choice is revealed; or you can have the character outright state it when it makes realistic sense to conversationally do so.
Some examples that come to mind:
- A Clockwork Orange: Alex (post treatment) does not quite have the words to express how his emotional state has changed. This is revealed through his (now changed) compulsive responses to certain situations, and some logical conclusions drawn by the reader/viewer on what the effect of such a treatment would be.
- The Dark Knight: Harvey Dent very much explains his newfound behavior, because he is actively choosing to behave this way out of anger towards the world he finds himself in. It would not make sense for him to do this and not grandstand about it.
- Marvel Cinematic Universe: Tony Stark often over-elaborates his points as a form of wit. However, what he doesn't quite reveal are the little things, such as why he is so fond and protective of Peter Parker. It is the absence of blatant explanation that makes it so interesting, specifically because he over-explains pretty much everything else. The absence of an explanation speaks more than his explanations would've.
- Memento: The entire plot revolves around finding out why Leonard kills Teddy, which seems like a very unjustified act when we initially start learning who Teddy is to Leonard. In the end, a blatantly simple explanation is revealed; but the viewer was sent on a long and puzzling quest before getting to that point. The joy was in the journey, not so much the rather blatant explanation in the end (or beginning, I guess).
- I can't think of a specific instance, but there are cases where someone is unjustly mean to someone who likes them. They don't want to hurt them, but they need to hurt the other person so that they can get them to leave the scene or do something they wouldn't otherwise do. The way this is revealed differs on the story. Sometimes it is contextually obvious to the reader/viewer at the time. Sometimes it is only revealed that this was the underlying motivation much later, during the redemption of that character who up until then had been assumed to be malevolent.