I don't think time is the issue, at least not by itself.
I tried sneaking, stealing a got and got into a fight, and the mayor was still ok after going upstairs. Same if I took a bit longer to loot (even clearing out the King Crab cellar), and didn't get into a fight. Tried going upstairs normally and in sneak mode.