I am far from an optics expert, but my understanding is when making a prime lens the lens designers are able to optimize for a specific focal length, when making a zoom lens the lens designers need to make tradeoffs throughout the zoom range to produce a balanced result. For example, a 24-70 zoom may trade off some sharpness at 70mm to produce acceptable sharpness at 50mm. Next faster lenses are usually sharper when stepped down. For example, an f1.8 prime might be sharper at f2.8 than a prime lens that is wide open at f2.8. Lastly, pricer optics usually have the best glass, lens coatings, and quality assurance. For example, the Nikon 14-24 f2.8 S has the Nikon Arneo coat, which the Nikon 14-30mm f4 does not.
Some extremely high IQ lenses, like the Voigtlander APO lenses also trade AF for MF to help optimize IQ in a small package.
Rember through that lens, like a lot of electronics, have a point of diminishing returns. I think it's safe to to say the Nikon 50mm f1.2 S is better than the Nikon 50mm f1.8 S but, unless f1.2 is critical for your use it's hard to say the f1.2 lens is 3.5x (the price difference) better than the f1.8 lens. Also, the f1.2 lens is larger and heavier, so it may not be as practical for your needs.