Is it ok to hide main motive of the character throughout the book? In my story, the main character never tells why he's doing what he's doing and the reader are fooled into believing he's doing it for a particular purpose until near the end the main character does a 180 degree and his action reveals what his goal was all along. Does this weaken the plot of a book or not? When the conflict, the climax and the rising action goes against the resolution and the hidden motive in the story, is this a bad thing?
With a Twist:
There's a whole vein of books and movies that are like this, in the thriller category. The MC is usually portrayed as a kind of mastermind, but sometimes the concealment is enough. While books can do this, I think of Lucky Number Slevin, Red Sparrow, and What Lies Beneath as movies where the end is a twist plot that flips the whole story on its end. You can have a character whose motive is undiscernible, more clever than they seem, or deliberately deceptive. M. Night Shyamalan's whole career is based on the twist ending.
So absolutely, you can have a main character deceiving everyone about their true motives right up till the last page! Particularly fun is the moment of the reveal.
But you can certainly disappoint your readers if the audience sympathizes with the false justification but not the real one. Nothing will offend more than a seemingly moral character you fall in love with actually being a scumbag. That's why characters that go that way are almost always supporting cast.
You should leave hints throughout the story, and these should (at least in retrospect) make the reader go "Aha! I see it!" If you come off making your reader feel stupid, they will not read another or recommend the book. You will need to do a bit of infodump at the reveal or shortly thereafter to explain the twist. Even Sherlock Holmes sits down at the end and explains to Watson how he got to the point he did, and this is definitely a mystery element. Otherwise, you will anger your readers who don't instantly make all the connections as to what just happened.
So done right, this is a great move. But it needs to be integrated, clever, and gentle on the reader. The character's motives should end up clear and sympathetic. And if successful, the reader should go, "I totally should have seen that coming!"
Other questions on this topic:
Are we getting his point of view?
Unless the character is seriously disturbed, and we can tell he is seriously disturbed, withholding important knowledge is almost certain to come across as cheating. If he is working toward a certain end, he's bound to think of it.
If he is viewed entirely from the outside, it can be feasible.
I think it depends on the POV of the story.
For instance, if your story is told through an omniscient POV where no interiority of the characters is revealed directly -- meaning that everything we know about the characters comes from their actions, inactions, reactions, absence of reactions, gestures, and dialog -- then the entirety of all of the characters' motivations are based on assumption. In this case, a end of story twist that puts the character's motivations and intents in a new light could be a terrific story that blows everyone's mind.
If the story is told in a 3rd person POV from the viewpoint of the character that is going to be doing the reversal of motives, then the more intimate the POV the more this will feel like a great big middle finger like the author is laughing at the reader screaming 'gotcha! fooled you! it was too easy, you stoooopid person' and most readers will likely not really enjoy it.
If the story is told from multiple POVs, including the deceitful motive character, then it might work well if those other POVs attribute differing motives to the deceiving character. Like some characters think that character is a scallywag and others think that character is a saint and others have different opinions, could make for a very interesting story. I think it would be important that in the scenes in the deceiving character POV that the focus of those scenes wouldn't be related to how that character is deceptive.
For example, A actually desires to murder B, but acts solicitous toward B claiming to respect and love them like a family member -- like how Edmund Dante acts towards some of his foes in the Count of Monte Cristo. But, the characters C D E ... Z all subscribe different motives to A. If the scenes in the A POV don't involve B then there is a plausible reason why A's motives are hidden from the reader.
There is a world of difference between a plot twist and a gotcha ending.
Plot twists happen to characters.
Plot twists make the story deeper because they reframe something that's been there all along. Characters' plans and beliefs are upended, friends are exposed as enemies, the MacGuffin is a red herring. Plot twists add tremendous conflict by putting characters in fresh jeopardy when actions they have already taken turn out to be wrong. Plot twists re-arrange the gameboard while the game is being played.
A plot twist serves the same narrative function as when a main character confronts their flaw in a 3-Act Structure. The original story elements are still in play, but the protagonist must adapt to a new understanding of the situation and the story changes direction. Genres where external events drive the plot don't require the protagonist to have character agency, therefore their flaws become less important as sources of conflict/antagonism.
In horror, detective mysteries, thrillers, and probably any story where a protagonist must survive an ordeal (man against nature, unjustly accused, war from a soldier's pov) the protagonist's internal state is a reasonable reaction to extreme events that are outside their control. The protagonist will be treated unfairly through no fault of their own. Character flaws will add drama, but an 'innocent' protagonist is more sympathetic.
A gotcha ending is a trick the author plays on the reader.
Gotchas do not change character motives or re-direct the action. They have no meaningful impact on the plot, rather the intended effect is the surprise of an unreliable world/narrator. It's a non-diegetic style choice done through the narrative voice. All the story elements stay the same, the reader just discovers they were misdirected through clever editing. Maybe some characters witness the reveal but it's too late for them to do anything about it, the end.
If the reveal invalidates the journey, it's a shaggy dog story. If it's too random/too obvious, there's no payoff just cringe. Discovering the character had magic armor all along is deus ex machina (or worse, Mary Sue). If brevity is the soul of wit then short stories/TV episodes are probably better. Certain genres are a natural for gotcha endings: spy games, meta/weird, conspiracy/paranoia, no-win gambits/doomed heists, not to mention comedy.
A grim-dark gotcha ending has a lot in common with the punchline at the end of a joke. The reader must be put in the right frame of mind, prepped through the narrator (the telling) to appreciate it. There are ways to signal a joke without revealing the punchline – your narrator will need to accomplish something similar.
Like a magic trick, a gotcha is not a prank pulled on the reader for shock value, it's a performance that should awe and delight. The reader should want to go back and factcheck what they read and be amused by what they thought was important, and discover something new in the clues they overlooked.
Does this weaken the plot of a book or not? When the conflict, the climax and the rising action goes against the resolution and the hidden motive in the story, is this a bad thing?
Plot twists are are an advanced type of plot. Some level of 'turn' should be happening to characters in every scene, but a plot twist is built on many of these scene turns where (later) the character discovers they've made the wrong assumptions. The road doesn't suddenly turn 90•, it twists and turns ramping up to danger. So generally a character relies on their compounded wrong assumptions a little longer than the reader does, creating suspense that's released by the twist.
A Gotcha is a 1-time effect that happens outside the text in the reader's mind. Unfortunately readers are as unreliable as narrators, so it takes a strong narrative style to pull it off. 2 well-known examples are:
The Sixth Sense
Both use an unreliable narrator to hide facts about the protagonist that would be obvious to other characters, and while the endings dramatically re-frame each story, their gotcha reveal doesn't actually alter the plot or the motives and reactions of other characters.
As a counterargument, I've actually seen it said that hiding the actual motivation of the main character throughout the book isn't a smart idea. I heard this said in regards to a comparison between Ed Brisson's The Ballad of Sang and John Wick. Both stories have very similar plots (a trained assassin going on a rampage because of a minor personal loss), but the former hides the character's motivation until the last couple of pages, whereas John Wick going on a rampage over his dog is front and center.
In The Ballad of Sang, on the other hand...
Sang seemingly goes after the big bad because he killed his mentor figure, but at the end it turns out that said mentor figure was violent and abusive to Sang and Sang actually wanted to thank the big bad for killing him, but the big bad also took Sang's action figure, one of the few things he had in life, and Sang wanted it back.
The problem with The Ballad of Sang is that throughout the entire story the reader is given no context as to the protagonist's motives. However, this ends up creating a story where the protagonist (Sang) is basically an unknowable enigma, the reader has no reason to care about Sang or his goals, and he is this completely unpredictable ball of violence that goes from one scene to the next without even the slightest bit of context as to why he takes the course he does. He's less a character with motives than a plot device.
Additionally, in order to do this the protagonist must be mute and uncommunicative, because if Sang was allowed to talk for any length of time, it would immediately become obvious what he is really after. This is especially pertinent if the story follows the protagonist's point of view, because it's very hard to keep one's true motive out of their own thoughts and point of view. Not saying its impossible, but it would require a masterful amount of doublespeak and a huge amount of deliberately-guided misinterpretation by the reader on part of the author.