Pretty straightforward two part question.
One: what is the definition of an RPG?
I'm going to assume that this definition is meant to include tabletop roleplaying games and exclude computer roleplaying games.
Definition
With that in mind, to my mind, a roleplaying game is:
- A game that is, by design, intended for the players (however many there are) to adopt fictional personas inhabiting an imaginative space they generate, and resolve the activities of those personas within that space.
- A game whose primary gameplay activity, by design, is the generation of new fictional states following from the declarations of the players.
- A game whose ruleset is partially unbounded due to some combination of (1) the fictional personas are not limited to the gameplay moves outlined in the rules, (2) the rules by definition include gameplay moves that intend to allow an effectively unlimited activity set, (3) the rules grant explicit or implicit permission to players to add to the ruleset. Restrictions on permissible declarations will follow from the implicit or explicit restrictions of the fiction (†), from the rules (††), or from the expectations of other players (†††).
Elaborating on the Points
Per point 1, nothing is stopping you (as others have noted) from roleplaying when you sit down to play chess, cribbage, or Unstable Unicorns. However, those games aren't really designed around roleplaying as the central activity of play.
Per point 2, games such as Last Night on Earth or to a lesser extent Twilight Imperium positively encourage roleplay. However, the primary gameplay activity of such games is not the generation of new fictional states.
Per point 3, games such as Horizon Zero Dawn, Baldur's Gate, Gloomhaven, or Arkham Horror (perhaps to a lesser extent as far as that last game is concerned) not only positively encourage roleplay but also are designed around roleplay, but inhabit bounded rulesets. You can only ever do what the rules (or code) say you can do, no more and no less. (Note that if you don't mind cRPGs qualifying as RPGs, you can remove point 3 from the definition.)
Notes from Point 3
(†) Such as how humans don't have an innate ability to fly in D&D. Also, contrary to what some poster wrote above, that fiction can, in fact, be written on your character sheet. For instance, if you want to dig through a dungeon wall in D&D, you had better either have a burrowing speed (possibly one allowing you to burrow through hard substances), or a pick and shovel in your inventory (which, you know, will be written down on your sheet).
(††) For instance, if you want to kill a dragon in D&D, there are rules that proscribe just how you go about doing so - you have to reduce its hit points to 0, cause it to gain six levels of exhaustion (in 5e), or subject it to some kind of "save or die" effect (and hope it fails its save), or what-have-you. Whatever the case, you usually can't just declare "I kill the dragon" and have it be so in the fiction -
something has to make the dragon dead, whether that something involves invoking fiction alone or also invoking game mechanics.
(†††) For instance, the rules certainly do not prohibit, say, a D&D DM from throwing together an encounter with a pile of giant spiders, but a DM with a player suffering from severe arachnophobia might rightly decide that leisure time activity is not meant to be exposure therapy and demur from doing so. Similarly, most tables frown on declarations of sexual activity that are explicitly detailed.
Two: does D&D fit that definition?
Yes. All D&D does.