I am a firm believer of the "the prophecy is right until someone proves it wrong" philosophy. Basically, a prophecy is the most likely outcome given the current situation and the various factions involved.
If you can change the situation enough, then the prophecy might become wrong.
It's basically the Intuition spell pushed to the extreme and wrapped into mystical mumbo-jumbo
But there are obviously things you can do to make your prophecy more resistant to PC actions
- be vague about what will happen
- do not specify a precise date
- if you can think of different, conflicting interpretations, that's better
- make sure that some people know of it and have already invested in either its resolution or its avoidance, in their own flawed way. If they have researched it, and tried to avoid it and failed, it gains significance and power just because people are convinced it *will* happen.
- use a prophecy in a world setting where most people believe in fate in some way (and it will likely be thwarted) OR in a world where everyone thinks they are just con jobs or fairy tales (and it will likely become true).
- if you want the prophecy to become true, don't make it the focus of the campaign unless the characters *want* it to become true. This preserves player agency. After all, if they are busy doing something else, the kingdom can meet its fate.
- if you want your players to go along and make it happen, reveal the prophecy only after they have already chosen what they will do - if they want to save the kingdom, reveal the prophecy that the tyrant will fall only as part of their search for a way to achieve their goal. Thus, they well not see it as railroading but as a clue. This is usually the midpoint of the campaign, where the characters go from "looking for a recipe" to "gathering the ingredients".