I think maybe I'm not the only one that's run into this problem before - more often in fanfic than in published novels, but... you know, not every novel is perfect.
You're reading along, minding your own business, enjoying a good story, when suddenly something happens that makes no sense. A character makes a decision that doesn't line up with what they've done before. Someone declares romantic interest in a person they haven't really interacted with before then. The author stages a torture scene that doesn't seem to move the plot anywhere.
This is something that's more often a tool of the Bad Romantic Subplot, but it can show up in other places, not because the author is a bad person or even because they're an untalented writer, but rather because they wanted that to happen. This can occur one of two ways.
A thing happens that could be convincing or even compelling, but there was no setup for the thing, so it felt like it came out of nowhere.
A thing happens that does not fit in the narrative, but is put in anyway for the sake of setting up something else, or even for its own sake.
The first is what happens when an author wants so badly to get to "the good part" that they forget to lead up to it in gradual steps.
The second happens when the author is so attached to a certain scene or concept that they're willing to sacrifice the continuity of the story up to that point to keep the desired scene/concept intact.
Now, it's important to keep in mind that wanting a certain scene or a certain character dynamic is not a bad thing. There's nothing inherently wrong with romantic subplots that they create these immersion-breaking moments.
It is, however, generally considered good practice to keep the established facts about your setting and characters consistent before, during, and after the desired scene. If the characters you wrote up to this point aren't the sort that can be in a romantic relationship without tearing each other apart, then either they will tear each other apart, or they will not be in a romantic relationship, because if you force them together and suddenly everything is hunky-dory, you have written two mannequins into the roles, rather than two living, breathing people.
This was not supposed to turn into a rant about romantic subplots, because this can happen in other places, too. Torture scenes, as mentioned before. A character being kidnapped and "damseled" so someone else can come rescue them. The rules of magic or technology suddenly changing for this specific circumstance.
This is a pitfall. Avoid it at all costs!