Legion (the Broken Isles) does have some PvP areas in each zone. There are some faction based ones around the Warden Towers and some Free for All ones in other areas. Generally, if you enter one of these areas you’ll get an alert that the area will flag you for PvP and a debuff will appear with a countdown. If you don’t get out of the area before then, you’ll get flagged. Fortunately, the enemy NPCs in the area won’t come after you unless you get within normal aggro range or attack them.
Other notable PvP zones are Wintergrasp in Icecrown, and the southern island of Tol Barad. (Neither of those have regular leveling quests so you won’t run into them while questing, but you do have to be careful flying over Wintergrasp as if there is an active battle you’ll be dismounted.)
The other time you’ll get flagged is if you enter an enemy city (the zone text will be red) or if you get to close to an enemy faction NPC. (And the guard NPCs are very often max level, so they hurt when you’re leveling.) It sounds like it was the second one that got you in Pandaria. The Hozen in Jade Forest are a bit spread out, and not all Hozen mobs are part of the Horde faction, so they are probably the “stealthiest” ones I can think of. They are all in that one area of the zone, though.
You can tell if an NPC is flagged for PvP by looking at their tooltip when you mouse over them. If they are PvP enabled, they’ll have “PvP” in the tooltip. You can see this in the friendly NPCs tooltips as well. (So you can see what to look for without risking getting too close to an enemy.) It will also show up when you target an NPC as they’ll have a horde/alliance icon on their target frame if they are flagged. (Just like the one that appears on your player frame when flagged.)
There are also some smaller enemy faction camps with over-aggressive guards. (I’ve been sniped from the road in Shadowmoon Valley by the Aldor npcs.) It’s just something you learn as you play. Some areas are dangerous! It’s not really all that common, but when it happens, it does stick out, so it can feel more prevalent than it is. I’ve had way way more deaths to falling off stuff in WoW than I have to accidentally getting too close to enemy NPCs.
In most cases, I find that your odds of encountering other players when you get accidentally flagged are pretty low unless you’re actively engaging in the PvP objective. So, you can just leave the area on go about your business while the 5 minute timer runs out. If being flagged bothers you, then getting on a flight path or entering a dungeon instance will immediately clear it. If you get killed, you can also wait out the PvP timer as a ghost and erectness unflagged. (Just make sure you’re not in a place that will immediately re-flag you.)
You’ll stay flagged for as long as you’re in an enemy city or PvP area. The timer on your PvP flag will reset back to 5 minutes if you attack a PvP flagged player or NPC, if you take a portal to a new area, or if you log out of the game.