We study the redshift evolution of the baryon budget in a large set of galaxy clusters from the Magneticum suite of smoothed particle hydrodynamical cosmological simulations. At high redshifts (z ≳ 1), we obtain ‘closed-box’ (i.e. baryon mass fraction fbar = Ωbar/Ωtot) systems independently of the mass of the systems on radii greater than 3R500, c, whereas at lower redshifts, only the most massive halos can be considered closed box. Furthermore, in the innermost regions (r < R500, c), the baryon fraction shows a general decrease with redshift, and for less massive objects we observe a much more prominent decrease than for massive halos (fbar × Ωtot/Ωbar = Ybar decreases by ∼4% from z ∼ 2.8 to z ∼ 0.2 for massive systems and by ∼15% for less massive objects in the same redshift range). The gas depletion parameter Ygas = fgas/(Ωbar/Ωtot) shows a steeper and highly scattered radial distribution in the central regions (0.5R500, c ≤ r ≤ 2R500, c) of less massive halos with respect to massive objects at all redshifts, while on larger radii (r ≥ 2R500, c) the gas fraction distributions are independent of the masses or the redshifts. We divide the gas content of halos into the hot and cold phases. The hot, X-ray-observable component of the gas accurately traces the total amount of gas at low redshifts (e.g., for z ∼ 0.2 at R500, c, in the most massive subsample, that is, 4.6 × 1014 ≤ M500, c/M⊙ ≤ 7.5 × 1014 and least massive subsample, that is, 6.0 × 1013 ≤ M500, c/M⊙ ≤ 1.9 × 1014, we obtain Ygas ∼ 0.75 and 0.67, Yhot ∼ 0.73 and 0.64, and Ycold ∼ 0.02 and 0.02, respectively). On the other hand, at higher redshifts, the cold component provides a non-negligible contribution to the total amount of baryons in our simulated systems, especially in less massive objects (e.g., for z ∼ 2.8 at R500, c, in the most massive subsample, that is, 2.5 × 1013 ≤ M500, c/M⊙ ≤ 5.0 × 1013 and least massive subsample, that is, 5.8 × 1012 ≤ M500, c/M⊙ ≤ 9.7 × 1012, we obtain Ygas ∼ 0.63 and 0.64, Yhot ∼ 0.50 and 0.45, and Ycold ∼ 0.13 and 0.18, respectively). Moreover, the behaviour of the baryonic, entire-gas, and hot-gas-phase depletion parameters as functions of radius, mass, and redshift are described by some functional forms for which we provide the best-fit parametrization. The evolution of metallicity and stellar mass in halos suggests that the early (z > 2) enrichment process is dominant, while more recent star-formation processes make negligible contributions to the enrichment of the gas metallicity. In addition, active galactic nuclei (AGN) play an important role in the evolution of the baryon content of galaxy clusters. Therefore, we investigate possible correlations between the time evolution of AGN feedback and the depletion parameters in our numerical simulations. Interestingly, we demonstrate that the energy injected by the AGN activity shows a particularly strong positive correlation with Ybar, Ycold, and Ystar and a negative correlation with Yhot and ZTot. On the other hand, Ygas shows a less prominent level of negative correlation, a result which is highly dependent on the mass of the halos. These trends are consistent with previous theoretical and numerical works, meaning that our results, combined with findings derived from current and future X-ray observations, represent possible proxies with which to test the AGN feedback models used in different suites of numerical simulations.