If You Are Grappled
If you are grappled, you can attempt to break the grapple as a standard action by making a combat maneuver check (DC equal to your opponent's CMD; this does not provoke an attack of opportunity) or Escape Artist check (with a DC equal to your opponent's CMD). If you succeed, you break the grapple and can act normally. Alternatively, if you succeed, you can become the grappler, grappling the other creature (meaning that the other creature cannot freely release the grapple without making a combat maneuver check, while you can).
You can do either with a successful CMB check. The +5 applies in either circumstance:
If your target does not break the grapple, you get a +5 circumstance bonus on grapple checks made against the same target in subsequent rounds.
That's "grapple checks" not "checks to escape a grapple." I know the flowchart says "to maintain," which is true but not complete, a flowchart doesn't mean you don't have to read the rules, and rules text always takes priority over tables or graphics (especially unofficial ones).
Yes, it's functionally equivalent when just grappled to escape, or to reverse it and then let go (barring other powers and abilities that proc in these situations). Also, if you're pinned, you can only try to escape, not reverse it.
It's not in the rules, but DMs have the latitude to allow it.
As you point out, I couldn't find anywhere in the rules to support an action like that. However, the system allows for DMs to make judgments about whether an action is reasonable/possible, as well as how difficult it is (PHB 192):
When you describe an action not detailed elsewhere in the rules, the DM tells you whether that action is possible and what kind of roll you need to make, if any, to determine success or failure.
This specific instance is probably balanced.
Thus, it's up to you as the DM to determine whether this specific case should be allowed. More specifically, we need to ask, "If creatures are allowed to do this, would they always do it?"
From a theorycrafting perspective, it seems roughly balanced. The effects of pinning a caster's arms (or any character's arms, really), is roughly comparable to Hold Person, which is a second-level spell. We can take a cue from Hold Person, and say that if we want the effect to last multiple rounds, the grabbed character should get an opportunity to escape every round (as if from a grapple). The rest of the balance is probably a wash, because such a pin prevents the attacker from doing anything else, but they can do it for free.
We can also look to the grappler feat, which does something similar (PHB 167):
You can use your action to try to pin a creature grappled by you. To do so, make another grapple check. If you succeed, you and the creature are both restrained until the grapple ends.
Consider that you're allowing any character to take the benefit of this feat for free, and that the effect you're trying to create is actually more powerful than this feat. I'm personally OK with this, given that my players don't really use feats, but it's ultimately up to you and your players.
I have used a similar rule in actual play, and it seems to be a bit underpowered compared to other possible actions. I had a few of my NPC characters try to grab and pin the PCs, both to prevent them from escaping and to incapacitate them. I required my NPCs to initiate a grapple with one action, and then make a contested strength check to pin them with another action. Because the process costs two actions, allows for two "saving throws", does no damage, and still permits verbal-only spellcasting, its opportunity cost is very high--imagine the damage that a strong creature could do in two rounds! Additionally, once they are pinned, the grappler cannot do anything else, which effectively takes them out of the combat. While such an action was appropriate for the situation, I cannot imagine a smart combatant wanting to do this with any frequency.
However, if you do include this rule, you should remember that it will affect your future combats. It might not make much sense to try this move if there are lots of enemies, but it can completely shut down a combat with a solo spellcaster, if they ever move within melee range. It will also open up this option to enemies restraining the PCs, which they might not be super happy about.
Best Answer
This is Improvising an Action, so the DM decides
But a Strength (Athletics) contest is most appropriate, although probably only as an action on subsequent turns
The first half of the plan, where the dragon grapples, lifts and drops characters from a height, is a valid tactic, covered by NautArch's answer and this question. Using solely the rules as written, there is no defence against this other than not getting grappled or being able to survive a fall (which probably won't do too much damage compared to the dragon's normal damage output. Dragons do enough damage that attacking is generally better than grappling. But the strategy is good for weaker flying creatures).
One thing that won't work for preventing a fall is grappling the dragon. The rules for Flying Movement (PHB 191) state that
As such, if the dragon decided to spend two turns to fly you into the sky, such that you got an action, you could attempt to grapple the dragon. However, that would stop the dragon from being able to fly and you would both plummet to the ground. This is clearly not what you want.
What kind of action or roll is needed to hang on?
What you describe - essentially preventing a creature from releasing its grapple on you - is not detailed anywhere in the rules\$^1\$. But, fortunately, there are rules for cases where there are no rules.
(PHB 193, sidebar)
Attempting to hold on to the dragon and not fall is a sensible action to attempt, so it is up to the DM to determine whether it is possible and what kind of roll needs to be made. Note that I use the term 'action' loosely here, but the principle of 'DM decides' is broader than just improvised Actions (see DMG page 4), so if as the DM you are feeling generous enough to allow your players to do something to try not to be dropped by the dragon you are explicitly empowered to do so.
This attempt to hold on sounds like some kind of Ability Check, so we can check PHB Chapter 7 for ideas (as recommended by the Improvising an Action sidebar). We find under Strength (Athletics) (p 175) an example that is very similar to your situation:
Under examples for Other Strength Checks, we also have
If you are feeling very generous, you might also allow the player character to use Dexterity (Acrobatics) to not fall, but the case for this is weaker than that for Strength. This task primarily involves lifting your own body weight against gravity and having a grip strength which exceeds anything the dragon is doing to make you let go. The best Dexterity can do is avoid the dragon's limbs trying to kick you off, but that's only a small part of the task.
This task is not a simple Ability Check, though. We have a situation where one creature is trying to prevent the other from accomplishing a goal. This means we want to use a Contest (PHB 174).
As such, if the player character wishes to hold on while the dragon attempts to drop them, it would be appropriate to call for a Strength (Athletics) contest between the two creatures.
On subsequent turns, when the dragon makes further attempts to drop the player character, you can call for more Strength (Athletics) contests. Although, there is some ambiguity as to what sort of action it would be for the dragon to do this.
\$^1\$ As demonstrated in Sdjz's later answer, I am actually incorrect in this assertion. The rules do describe a very similar situation: the rules for climbing onto a larger creature. The player character needs to make a Strength (Athletics) or a Dexterity (Acrobatics) check as an action contested by the dragon's Dexterity (Acrobatics) to cling onto the dragon. The dragon can later attempt to shake off the player character by taking an action to make a Strength (Athletics) check contested by the player character's Strength (Athletics) or Dexterity (Acrobatics).
I retain my prior discussion on Improvising an Action, though, because this kind of thinking is useful for on-the-fly rulings when you want to do something and aren't sure if there are any rules for it.
Balance and action considerations
The sort of roll we want is a Strength (Athletics) contest, but we need to sort out when we should call for this roll.
You may be concerned in thinking that this tactic is extremely dangerous and has no counter so needs a counter. However, let us consider what the dragon has to do to pull off this strategy even without your houserules.
First, the dragon has to use their entire action to attempt to Grapple the target. Unlike player characters who have Extra Attack, monsters have Multiattack, which explicitly state which attacks the monster can use with it. Between Multiattack and their Breath Weapon, dragons are able to deal a terrifying amount of damage with their action.
So let us consider how much damage this strategy can normally do. Dragons (older than Wyrmlings) have a flying speed of 80 feet, so on flat terrain this would do a paltry 8d6 damage (average 28). This is less than the expected damage per round from a dragon's normal attacks.
Of course, dragons do not always live on flat ground. If a handy cliff is nearby, the dragon might try to drop the creature over the edge for up to 20d6 (70) damage. The damage is a little more than what a dragon can normally do, but the real risk is taking the character out of the fight due to distance. If this is the hazard, you may be inclined to rule in favour of the players. Alternatively, you can make clear that falling is a very real environmental hazard as your players approach the dragon's lair by emphasising the sheer drops and mentioning how they wouldn't want to get knocked down there. It would then be up to the players to prepare appropriate countermeasures (such as feather fall, dimension door, fly, climbing gear, luring the dragon to the bottom of the cliff, or simply not being close to a cliff during the fight).
Note that to succeed in this plan, the dragon has to successfully grapple the character. This is not a given. While dragons have Strength ranging from very good to exceptional, they are not proficient in Athletics. Any character with good Dexterity (Acrobatics) or Strength (Athletics) has a roughly 50-50 chance of avoiding the dragon's grapple, completely wasting the dragon's turn.
Note that the dragon would also provoke opportunity attacks as they attempt to fly away. This doesn't stop the dragon's plan, but it does add an extra cost to it.
In grappling the character, the dragon has already faced a risk of failure, and the character has already failed on their roll. To require further checks on the same turn to let go of the grapple would be extraneous. If the character were standing next to a cliff and someone else succeeded on the contest to Shove them, then that character would fall off a cliff. This circumstance is no different, except with a longer range.
What I would do is make the player character spend their action on their turn to hold on to the dragon with the aforementioned Strength (Athletics) contest, in a similar style to grappling (except it isn't grappling or an attack). If the player succeeds then the dragon can't drop them until the dragon uses an action to succeed on another Strength (Athletics) contest, or until both the dragon and the player character choose to release their holds. By doing it this way you sort out the action economy of this strategy.
This doesn't help the player if the dragon drops them on the same turn as they grappled. But, unless the fight is taking place right next to a very tall cliff, the dragon may need to spend an extra turn of movement to make the drop worth the effort. The dragon might also choose to delay dropping until the start of their next turn so that they can swoop down on the freshly prone creature and attack with advantage.
Even if the fight is taking place next to a cliff, you can decide to have the dragon not drop the character until the dragon's next turn. This could be rationalised as the dragon ensuring that the falling character will clear the slope of the cliff. But the real reason is to give the players a chance to react to this dramatic scene.