  The chemical enrichment of dust and metals are vital processes in
constraining the star formation history of the universe. Previously, the dust
masses of high-redshift star-forming galaxies have been determined through
their far-infrared continuum, however, equivalent, and potentially simpler,
approaches to determining the metal masses have yet to be explored at $z\gtrsim
2$. Here, we present a new method of inferring the metal mass in the
interstellar medium (ISM) of galaxies out to $z\approx 8$, using the
far-infrared [CII]$-158\mu$m emission line as a proxy. We calibrated the
[CII]-to-$M_{\rm Z,ISM}$ conversion factor based on a benchmark observational
sample at $z\approx 0$, in addition to gamma-ray burst sightlines at $z>2$ and
cosmological hydrodynamical simulations of galaxies at $z\approx 0$ and
$z\approx 6$. We found a universal scaling across redshifts of $\log (M_{\rm
Z,ISM}/M_\odot) = \log (L_{\rm [CII]}/L_\odot) - 0.45,$ with a 0.4 dex scatter,
which is constant over more than two orders of magnitude in metallicity. We
applied this scaling to recent surveys for [CII] in galaxies at $z\gtrsim 2$
and determined the fraction of metals retained in the gas-phase ISM, $M_{\rm
Z,ISM} / M_\star$, as a function of redshift showing that an increasing
fraction of metals reside in the ISM of galaxies at higher redshifts. We place
further constraints on the cosmic metal mass density in the ISM ($\Omega_{\rm
Z,ISM}$) at $z\approx 5$ and $\approx 7$, yielding $\Omega_{\rm Z,ISM} =
6.6^{+13}_{-4.3}\times 10^{-7}\,M_\odot\, {\rm Mpc}^{-3}$ ($z\approx 5$) and
$\Omega_{\rm Z,ISM} = 2.0^{+3.5}_{-1.3}\times 10^{-7}\,M_\odot\, {\rm
Mpc}^{-3}$ ($z\approx 7$). These results are consistent with the expected metal
yields from the integrated star formation history at the respective redshifts.
This suggests that the majority of metals produced at $z\gtrsim 5$ are confined
to the ISM of galaxies.
