The cosmological evolution of metal enrichment in quasar host galaxies