Heavily group and game specific
This is something that is intentionally left vague, because every group has different ways they want to go about it. You’re basically right when you say they’re “a way for the DM to tell the players they're ‘doing it right’” – that’s basically all they really are.
XP is a reward, the most intangible and DM-adjudicated reward. Loot, favors, plot, those all depend on certain events happening, certain characters or objects being present, and so on. Those are things that sometimes the DM may have to give out for consistency’s sake even if the players didn’t really “earn” them, because the events of the story would make no sense if the players didn’t get them. Far more commonly, the players may have “earned” a reward, but those things wouldn’t make sense to appear.
So in comes XP. It’s something totally up to the DM. Most agree that killing monsters should give XP, and there are rules for how much XP a given creature is worth that, if followed, will generate a leveling rate that the system’s designers felt was appropriate. Pathfinder even has alternate XP tables for fast or slow leveling, if you want alternate rates. But you could just as easily decide to make things “super fast” or “super slow” by giving more or less XP. You can decide that certain methods of killing don’t count, certain methods of not-killing do count, and so on, and that will affect both the level-up rate and the sorts of behaviors that you encourage the players to do.
All of this works best when the players both understand and agree on the things that will and won’t get them XP. A DM who is seen as being “stingy” with XP may, with many groups, cause some resentment. At extremes, it may cause considerable dissatisfaction with the game (“jeez, we have been playing for like a year and we still haven’t leveled up even once!” – plenty of games go very smoothly with such a slow rate because players are aware of and on board with that, but since most games are faster many players will be surprised and unhappy with it if it isn’t communicated ahead of time).
So just talk to your players. If you tell them they’ll get the same XP for running away as they would for killing, they’ll be much more likely to use tactical retreats – which can free you up to use more dangerous monsters and trust the players to use sound judgement, but also could lead to overly-timid players unless you have a strong plot-related reason for them to get past the monsters. If you tell them they only get the XP if they get past the encounter, but they don’t necessarily have to kill it, they may invest heavily in stealth or forms of travel that allow them to skip enemies – this can be clever and interesting, and improve the game, or it can mean the players rarely actually interact with enemies and that can be boring. If you tell them they have to kill things to get XP, expect them to go hunting for things to kill, to default to violence as the solution to all problems, and so forth.