I’m about to throw an adult dragon at my players, one that is using the variant spellcaster rules (7 spells, cast each once per day at 5th level). I was wondering, would it be able to cast any of its spells using a Legendary action?
By the rules as written, no.
The dragon's legendary actions are what they are, and none of the options allow you to cast a spell.
By balance, probably not.
If you look at what legendary actions can do, it's usually less than a normal action during the dragon's turn. For example, a single Tail attack that deals 2d8 damage versus the Multiattack that has a 2d10 bite plus two claw attacks, and also triggers Frightful Presence.
A 4th level spell might not be as good as Multiattack (arguably), but it's going to be a lot better than a single Tail attack, and honestly it's probably significantly better than the Wing Attack that takes two legendary actions.
Options for doing this
It might be okay allowing a dragon to cast a spell as 2 or 3 legendary actions, but it sort of depends on what spells you pick out. Being able to cast powerful spells in addition to all the other "dragon" stuff can be a pretty devastating combo, and being able to cast two powerful spells in a row (more or less) is pretty dangerous as far as balance goes. (For the flip-side of this, let two PC spellcasters, like say a Cleric and a Wizard, fire off their top level spells one after the other and see how much that can disassemble a fight!)
Throwing down a direct damage spell is actually not that big a deal in this case because, frankly, it's a dragon with a breath weapon that's already a much bigger area damage effect. But tossing out a nasty crowd control effect, with a little strategy, could easily wreck the whole encounter for even a fairly high level group. A green dragon could, for example, cast cloudkill around itself and be effectively immune to the spell's effects (via blindsight and immunities), and a wall of force or stone could could quickly become an inescapable "I kill party members" trap for any dragon (lock one or two party members in a box with a dragon while the rest of the group can't help them).
I would be very wary of anything that would let the dragon cast two level 5 spells in a round. If you're planning to "doublecast", then as the DM you should consider carefully what spells you might do that with and what the implications are. There are existing creatures that have legendary spellcasting, but in general they either have second-rate spellcasting options (such as the Moonstone dragon in Fizban's, whose spells are either essentially non-combat or fairly low level), or the spellcasting is the whole point of the monster and their physical capabilities are second rate, so getting to fire off two spells per round is about the only thing that makes them a boss battle to begin with.
Which is all to say: A dragon is already a very dangerous boss battle, be cautious about giving it an extremely flexible extra ability and the ability to use it repeatedly in a round.
There are precedents in the official manuals.
Remembering that the DM has a huge freedom when creating a monster, they can decide to design a monster whose list of Legendary Actions includes also spellcasting. If the DM feels that this may increase too much the difficulty of the encounter, they can decide that such Legendary Spellcasting costs two actions.
It might be required also to adjust the CR1, following the rules in the DMG for creating a monster, computing the expected damage per round considering the Legendary Actions (see How do legendary and/or lair actions affect the CR of a creature I am creating?).
The official material presents monsters with this option, moreover some of them are also dragons. For example, the Adult Moonstone Dragon stat block reports:
The dragon can take 3 legendary actions, choosing from the options below. Only one legendary action option can be used at one time and only at the end of another creature’s turn. The dragon regains spent legendary actions at the start of its turn.
Tail. The dragon makes one Tail attack.
Cast a Spell (Costs 2 Actions). The dragon uses Spellcasting.
1 In my humble opinion, CR is a poor tool for adjudicating the difficulty and/or the challenge of an encounter. It could be a start, but knowing your party's strength and weaknesses and properly exploiting monsters' abilities provide much more insights on the possible evolution of the encounter.