XP is D&D’s reward systems.
This depends on edition. It's true for Gygax's AD&D. It may or may not be true in 2nd-ed era, Dragonlance-style play, depending on the conventions that apply at a given table. It's not true for all those 5e tables using "milestone" XP. In my own experience it's not true for 4e, where - especially once the full suite of XP rules from the DMG, DMG2 and Essentials is being used - XP is basically a pacing mechanism, basically a precursor to "milestone" levelling but less dictated by GM opinions as to when a milestone has been reached.
'Gaming the system' is a very real thing, whether the system in question is not meant to be a game (the more typical usage of the idiom, really), or is an actual game just not designed to be robust when "played" in that way.
"Gaming the system" can be a real thing in (say) electoral politics, or filing tax returns.
But what does it look like in chess? Monopoly? Backgammon? Forbidden Island?
Or, to focus on RPGs, what does "gaming the system" look like in Runequest? Dungeon World? Classic Traveller?
A game of Traveller in which all the PCs wear battle armour and fight with man-portable fusion guns is likely to be unsatisfactory for any sort of long term play, I would say, because the mechanics start to break down at that point. But that wouldn't be "gaming the system", because it's not like the participants get any benefit from having the mechanics break down - if they're all there for a fun time, then playing the game at the fun-reducing limits is self-defeating!
Players will generally do what ever gets them the most reward for the least effort. So “powergaming,” in a game where you get XP for killing stuff, looks like optimosimh your character to be as good at killing stuff as possible. In a game where you get XP for discovering new points of interest, “power gaming” looks like maxing out Perception and Investigation and maybe Survival, avoiding already beaten trails, and following up on every lead that might indicate an undiscovered location. If you understand your game’s incentives, you can use them to make power gaming work for you.
Classic D&D awards modest amounts of XP for defeating monsters, and significant amounts for recovering gold. These establish a type of "victory condition". So building a character, and playing, so as to increase the likelihood of defeating monsters and recovering gold, is good play. Gygax, in the concluding section of his PHB (under the heading "Successful Adventures", and coming just before the Appendices), gives advice on this. The
character building parts of his advice take the form of choosing the right equipment, including magic items, the right spell load out, and the right mix of PCs (because in classic D&D different PCs bring different class abilities, different spell load outs, and different magic items). The
skilled play parts of his advice pertain to setting objectives, mapping, making sensible decisions in relation to wandering monsters, and other aspects of dungeoneering.
It seems strange to me to call all the above "powergaming". Gygax clearly frames it simply as "playing well" - from his PHB, p 109:
If you believe that ADVANCED DUNGEONS & DRAGONS is a game worth playing, you will certainly find it doubly so if you play well.
The notion of "powergaming" seems to me to have two (I think related) origins:
(1) non-D&D players, of systems like RQ or C&S or RM, making fun of Monty Haul-type D&D play, characterised by extensive magic item load outs and ease of victory over opponents that, in the fiction, should be challenging (like balrogs, demon princes and the like) - for reasons to do with both system and play culture you don't find much of this in RQ or RM (you do find it in a system like Rifts, though, and hence players of RQ, RM and the like will also make fun of Rifts play as "powergaming") - this usage was later taken up by WW (and similar) players to mock a wider range of FRPG players, but essentially along the same lines;
(2) D&D players who play in the DL/2nd ed style, rather than classic skilled play, trying to manage the tension between the sort of RPGing they want, and the essentially Gygaxian rules system they are using, and in the process distinguishing themselves from the targets of usage (1).
The first of these uses of powergamer has become, I think, uninteresting. Those particular arguments about RPG culture, whatever their merits or demerits at the time, are done.
The second of these uses continues, however, among D&D players - you can see it on these boards - and I think the reasons are much the same now as they were 30 years ago. The mechanics of the game establish victory conditions, and so playing well means playing with those conditions in mind, but either (i) some of the game's systems break under pressure (and applying that pressure isn't any obvious sort of deviation from or corruption of the game's intended play), and/or (ii) pursuing those victory conditions does not generate the RP experience a significant part of the play community is interested in.
The mismatches and limitations of the 1980s were mostly due, I would say, to a lack of design experience and a conservative inclination not to change the system even when it was not fit for what it was being used for. These days the first of those reasons clearly doesn't apply, but the second appliles more strongly than ever!