The history of chemical enrichment in the intracluster medium from cosmological simulations