Yes, you can true polymorph a creature into a spell casting NPC
The rules text is pretty clear about this.
You transform the creature into a different creature ... The
transformation lasts for the duration, or until the target drops to 0
hit points or dies. If you concentrate on this spell for the full
duration, the transformation lasts until it is dispelled.
Creature into Creature. If you turn a creature into another kind of
creature, the new form can be any kind you choose whose challenge
rating is equal to or less than the target’s (or its level, if the
target doesn’t have a challenge rating). The target’s game statistics,
including mental ability scores, are replaced by the statistics of the
new form. It retains its alignment and personality.
The creature is limited in the actions it can perform by the nature of its new form, and it can’t speak, cast spells, or take any other action that requires hands or speech, unless its new form is capable of such actions.
If you want to True Polymorph a level 12 or CR 12 creature into an Archmage NPC, CR 12, you can do it, and it will be able to cast its spells.
Archmage (SRD p. 395)
Medium humanoid (any race), any alignment
STR 10 (+0) DEX 14 (+2) CON 12 (+1) INT 20 (+5) WIS 15 (+2) CHA 16 (+3)
Challenge 12
Spellcasting. The archmage is an 18th ‐level spellcaster. Its spellcasting ability is Intelligence (spell save DC 17, +9 to hit with spell attacks). The archmage can cast disguise self and invisibility at will, and has the following wizard spells prepared:
{Bolding mine, spell list edited out for brevity}
For example, could you create a Nothic with Wizard levels?
See this answer for a detailed breakdown of what's in a creature's stat block.
If you look at the Nothic's stat block, you don't find the spell casting ability, so that CR 2 creature would come as is - without spell casting.