Class levels are part of your stat block
at least for any class that qualifies you as a 'spellcaster'
Do you retain class levels when true polymorphed? The top-scoring answer here says "Well, you definitely retain your class levels. If someone casts Dispel Magic on you, you'll become a level 20 Sorcerer."
But I don't think that is the sense of 'retain' that the OP is asking about. Of course your don't permanently lose your class levels - they still exist 'somewhere' and are again accessible if your true polymorphed form is removed. The question is whether, while polymorphed, you currently have a class and are a certain level.
That answer continues, "However, True Polymorph does not allow you to use your class features (including the Spellcasting class feature)." This perspective, that your new form still is your old class, it just can't use class features, is a popular view, both here and at the question Can a polymorphed creature use class features that don't require speech or hand gestures? I don't think that view is correct, though.
Polymorph / true polymorph say:
The target's game statistics, including mental ability scores, are replaced by the statistics of the chosen beast. It retains its alignment and personality...
Wild shape also includes a part about changing to the creature's stat block:
Your game statistics are replaced by the statistics of the beast, but you retain your alignment, personality, and Intelligence, Wisdom, and Charisma scores.
So the basic format of polymorph and wild shape is: 'the new form's stat block overwrites everything, with the following exceptions'. And for Wild Shape, one of the exceptions is
You retain the benefit of any features from your class, race, or other source and can use them if your new form is physically capable of doing so.
Note that it does not say that you retain your class, or levels, just that you retain the benefits of class features. Thus the central question here for me is whether or not assuming the stat block overwrites your class and levels. If assuming the new stat block means that you no longer have a class or level, then under polymorph you simply don't have them, while under wild shape you still don't have them, but you are allowed to use the benefits of a class that you don't currently have. This is a different position than that taken by the popular view that under polymorph you still have a class and levels, you just can't benefit from them.
Why do I think that class levels are part of your stat block?
Because they are specifically listed for some stat blocks
The Monster Manual, in explaining what the parts of a stat block are (p. 10), says:
A monster with the Spellcasting class feature has a spellcaster level and spell slots, which it uses to cast its spells of 1st level and higher (as explained in the
Player's Handbook). The spellcaster level is also used for any cantrips included in the feature.
Suppose you polymorph into a Priest. As part of its stat block, it explicitly says "The priest is a 5th-level spellcaster." This stat block overwrites anything that previously existed on your character. If you were not a spellcaster before, now you are. If you were a 10th level spellcaster before, now you are a 5th level one.
But, is 'spellcaster' really a class? Can't you still be a 10th level wizard (who you actually are) and a '5th level spellcaster' (the stat block you now have) at the same time? The DMG explains that a spellcaster is simply a character who has the Spellcasting feature. For example (DMG p. 288)
The number of spell points you have to spend is based on your level as a spellcaster, as shown in the Spell Points by Level table.
Further, the number of magic items listed that can only be attuned to 'by a spellcaster' shows that the term 'spellcaster' is generic and encompasses a number of different classes.
Thus, because the monster stat block includes your spellcasting level, the stat block must overwrite your class and level (at least for any classes with the spellcasting ability).
Hence polymorph removes, and in some cases replaces, your class levels.
To the OP's question, "does the sorcerer retain their class-given spellcasting ability?" I would answer,
No: not because they retain the sorcerer level and lose the spellcasting ability, though, but because they have actually lost their sorcerer class and levels while polymorphed.