5th-9th level seems like a good sweet spot
When considering how balanced a Flameskull is compared to the PC whose companion it is, there are several factors we need to consider. Since it's a spellcaster, the obvious place is its spell list and slots.
A Flameskull has three 1st-level slots, two 2nd-level slots and a 3rd-level slot. Contrast with a 5th level spellcaster PC, who will have four 1st, three 2nd and two 3rd. The skull has one slot of each level fewer than an equivalent caster, but it offsets this via resistance to lightning/necrotic/piercing, immunity to cold/fire/poison, immunity to several conditions, and getting advantage on saving throws vs spells.
Looking at the offensive spells it's able to cast, it has Magic Missile, Flaming Sphere and Fireball. That means that via its spell slots, it can deal 8d6 damage in an area on one round (8-48 damage), 2d6 damage twice (or 3d6 once, for 2-12 or 3-18 damage) or 1d4+1 damage 3 times, 2d4+1 twice and 3d4+1 once (2-5, 3-9, 4-13).
It also has Multiattack, allowing it to use Fire Ray twice, so that's 3d6 fire damage on a hit (potentially 6-36 damage in one round)
All in all, these should be pretty solid attacks against enemies your party will be fighting at that level.
Given a hit die of d8 for a spellcaster with a +1 con modifier, at 5th level they'll have between 17 and 45 hit points depending on how good their rolls were. Flameskulls have 9d4+18 hit points, so have a range of 27-54, meaning they're potentially a bit more survivable than your average spellcaster, and are even sturdier thanks to the aforementioned resistances and immunities. This means your Flameskull companion shouldn't have any more trouble dealing with threats than party spellcasters.
With a 13 AC it'll probably get hit a lot by melee, but since its attacks are pretty much all ranged it's going to want to stay out of the front line anyway (which should be pretty easy with its 40ft fly speed).
It makes a pretty strong persistent companion as well due to Rejuvenation, so I'd say at 4th level it's probably too survivable. Our spellcaster PC at 4th has a range of 15-36 hit points.
At 6th level the hypothetical PC's top HP range matches that of the Flameskull, but it'll be falling pretty far behind on spell slots. Should still be okay. It'll start falling behind fairly far at 7th and 8th level, but its resistances, immunities and bounded accuracy mean that it should still be able to hold its own (bounded accuracy is the concept that bonuses on ability scores don't grow too much between levels, meaning that theoretically there shouldn't be too big a disparity between kinds of threat you can face from level to level, at least not to the ant vs god level of previous editions)
I think once you get to 9th level it's going to be too weak to really be useful against a lot of things, and will likely be taking significantly more damage than it can deal with, especially since caster PCs will now have access to casting 5th level spells, and that opens up a lot more offensive and utility possibilities that the Flameskull just can't match.
Another thing to keep in mind is that, as an NPC rather than a familiar, the Flameskull will gain a share of the party's XP, which will result in them levelling more slowly (though your DM might decide the Flameskull is able to gain levels and become stronger, in which case this may not be a bad thing).