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
If a flying creature... has its speed reduced to 0... the creature falls, unless it has the ability to hover or it is being held aloft by magic, such as the fly spell.
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.
Improvising an Action
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.
(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:
You attempt to ... cling to a surface while someone is trying to knock you off.
Under examples for Other Strength Checks, we also have
Hang on to a wagon while being dragged behind it.
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.