As a player, a big part of the fun in a tabletop rpg is to interact in a meaningful way with the fictional world : to make meaningful choices. To make sure that players get to do just this, the GM’s role is to offer them situations, ask them “what do you do”, then determine the consequences (through roleplay, dice-rolling, whatever). Wash, rinse and repeat. On a big scale, failing to do that has a name : railroading . The GM already decided what will happen with the queen (she rules the kingdom with an iron fist), so the first two steps are hollow (if they happen at all) : all the actions from the players will have no impact on it (if they raise an army, the queen will crush it, if they try to assassinate her, she’ll foil the plan, whatever).There is no shortage of articles on how this is bad and how to avoid it.
On the small scale, though, I’m not aware of any term, so I’ll go with railsurfing. It’s basically the same, but the thing the GM already decided is some specific consequence (loss of HP, loss of an item, some status effect, etc.) or setup (an ambush, a double-cross, etc.) The effect of this on the quality of the game can be just as dire as railroading, so we need to think about it, too.
Take the surprise trap for example : a PC walks in a room, activate a trap, and lose some HP. The PC did not get any meaningful choice about falling victim to the trap or not. Same goes with the ambush : a party walks in a forest, falls in an ambush, lose some HP. Again, no meaningful choice about being ambushed or not. Adding some reaction roll to mitigate the consequences (like a dice roll to limit damage or to be able to act right away) does not give a choice; it only reduces the effect of not having one.
A way to avoid this is to make the ambush or the surprise trap the consequence of a previous choice : “You can go through the forest, but it’s full of monsters that may ambush you; or you can take the boat, but there are pirates”; “You can go in the mansion, but stay alert : it’s full of traps”. From a player’s standpoint, it’s much better : what happens is not pure GM fiat, but the consequences of the choice they made. Of course, that information needs to have a real impact on the word. If the players know that there may be an ambush in the forest and stay on their guard, the GM must give them at least a real chance to avoid the ambush (by rolling to spot the bandits before they attack, for example).
Unless the GM want to slow the game down to a slog, they should also assure the players that saying that their PC is cautious is enough. If not, a player may insist on rolling a trapfinding skill before taking every step. Skip this and say “before you enter this room, roll your trapfinder skill to know if you spot the trap in time”.
That leads me to believe that the best course of action (at least in games where the PCs are minimally proficient at what they do) is for a GM to always tell players what will happen just before it does, unless they make a choice to be careless. It’s basically reversing the “burden of choice” : PCs are always appropriately careful unless they choose not to be. So in the mansion, a PC sees the trap a fraction of a second before it sets, and can try to disarm it; a PC recognize this place in the forest as the perfect spot for an ambush, so can try to spot hidden bandits to outsmart them.
That proviso should not be abused : putting traps in a place where the PCs will almost certainly come rushing (because there will be a deadly monster chasing them there) is not really giving the players a choice; it’s not railsurfing the same way that a GM deciding the Queen secretly always wear an amulet of invincibility is not railroading. The PC choosing to run from the monster by going forward instead of backtracking (“if you run in this hallway, you cannot stay alert for traps. Do you still do it?”) is absolutely ok, though.
Those ways to avoid railsurfing are not mutually exclusive. And none of them shield PCs from harm : they can act, but their actions can still fail (through roleplaying, dice-rolling or whatever). What they shield them from are the moments where they are hapless victims, and I see that as a good thing.