Though, isn't HQ-12 in a completely different class to S-300PMU2? AFAIK S-300PMU2 is more in class with HQ-9 while HQ-12 is a medium range air defense.
Yes, but it's older as well.
I am not OSINT bro and I can't say if it's the case in practice, but it probably made sense to first move older high-tier SAMs to secondary directions, where they're in turn replaced by more appropriate secondary systems and not just HQ-9 rotation.
HQ-12 was not so much medium range(it's more towards long, especially for 2000s-2010s) as it was a cheaper/simpler HQ-2 replacement. As such it wasn't better for secondary positions per se, but it was possible to procure enough of them from domestic manufacturing for reasonable money.
HQ-20 is actually better for the role - way more ammo (LACM intercept), can provide ABM, range is matched to stealth aircraft engagement capabilities(which it has); finally, no huge minimum range of S-300/HQ-9 series, you can pack one system instead of two and expect things to be covered for the time being (or, in a brave new drone world, rather 2 instead of 3). It doesn't need HQ-11, and overall has much smaller footprint.
Much like S-350, which is all the exact same logic (it replaces older rearline S-300PM batteries in the rear).