If the players want to do something I don't feel ready to do (either because it's not prepped or I don't feel up to winging it), I'll tell them.
"That's cool you want to go to so-and-so, but I haven't given it any thought. We can end early, or I can try to improv it with no quality guarantee"
There are some kinds of planning I don't do, like making specific maps and stat blocks, so some kinds of "going off script" don't hinder me much.
Sometimes I'll ask the players for input. "Ok, what sort of rites happen at this midnight ritual [that we just made up] that you decided to crash?". I don't really like the player mode where they just want to sit back and be told a story, nor do I much like the mode where they're super zoomed in on their character without engaging with any other level. I've had players like that, where they want to really immerse in their character and feel like answering setting details takes them out of it, but that's not really how I like it.