....
It is a problem waiting to blow up in your face if you have "unwritten rules" that the players and their characters will only discover by transgressing them.
For instance, if you dangle a little girl in distress in front of them and expect the PCs to drop everything to help her find her lost kitty, and punish them if they continue with their Important Mission, your game will break down as the players begin playing defense to protect their characters, and playing offense against you - instead of working with you to create an entertaining story.
This seems to be a different issue?
1. "unwritten" rules are bad (I can't even think of any exceptions at the moment) - the players should know the rules of the game before the game starts. If a known rule rule proves problematic the DM should initiate a discussion as to what the problem is and change the rule if necessary.
2. The above example seems to be a narrative issue rather than a mechanics one. An issue where the DM wants his campaign to go in a certain direction, and only that direction,- but didn't bother telling the players. This is also bad because the player and DM have different expectations. Punishing the players for expectations they don't even know about makes no sense! But it's different than the OP scenario because the DM isn't changing the rules on the players - he's enforcing rules he never disclosed - something that I just can't think could ever be a good idea - certainly not in 5e!