Remember that the plot twist has to make just as much sense as the non-twisty plot the reader is expecting. Ideally, it makes more sense.
Generally, there are two ways to make a plot twist.
The first is to make the MC misunderstand things. For example, they think the demon king is evil, but once they confront him, he turns out to be very nice and it is actually a conspiracy made by the human kingdom.
In this case, it is very important to lead into it, so that in hindsight, everything makes sense.
Introduce things that don’t quite make sense with the established narrative, let the characters and readers question some things but have not enough clues to come to the correct conclusion, so that when rereading your book, one can say “oh, so that’s why that happened!”.
If the reader figures out the twist in advance it will make him feel smart, which isn’t so bad, but if the twist is not telegraphed/logical enough, he will feel lied to and disappointed, which is very very bad.
The second way is to have everything set up, with the readers having a clear view of what will happen. For example, the world is preparing for war, and everyone has plans we are more or less aware of. Then, introduce a small wrench in those plans, someone doing something that leads to a domino effect, making a huge mess of the situation and suddenly ruining all the preparation, planning and theories of everyone,
In my war example, it could be some king getting assassinate for some personal reason unrelated to the global situation, suddenly weakening that kingdom and drastically altering the political landscape outside of everyone’s expectation. Note that it is still important to lead up to it, we should have been made aware of those personal feuds long before they are made relevant.
Lastly, you can use the meta against the reader. Like in games of thrones, it wasn’t that surprising that ned stark was executed, but he was one of the main characters, and the plot showed ways for him to survive, so I assumed he would be alright. He wasn’t.
In the end, the most important thing is to make sure that your plot twist is strengthening your plot, making it more cohesive and deep, instead of just making the reader go “oh, I wasn’t expecting that”