  We investigate what drives the redshift evolution of the typical electron
density ($n_e$) in star-forming galaxies, using a sample of 140 galaxies drawn
primarily from KMOS$^{\rm 3D}$ ($0.6\lesssim{z}\lesssim{2.6}$) and 471 galaxies
from SAMI ($z<0.113$). We select galaxies that do not show evidence of AGN
activity or outflows, to constrain the average conditions within H II regions.
Measurements of the [SII]$\lambda$6716/[SII]$\lambda$6731 ratio in four
redshift bins indicate that the local $n_e$ in the line-emitting material
decreases from 187$^{+140}_{-132}$ cm$^{-3}$ at $z\sim$ 2.2 to 32$^{+4}_{-9}$
cm$^{-3}$ at $z\sim$ 0; consistent with previous results. We use the H$\alpha$
luminosity to estimate the root-mean-square (rms) $n_e$ averaged over the
volumes of star-forming disks at each redshift. The local and volume-averaged
$n_e$ evolve at similar rates, hinting that the volume filling factor of the
line-emitting gas may be approximately constant across
$0\lesssim{z}\lesssim{2.6}$. The KMOS$^{\rm 3D}$ and SAMI galaxies follow a
roughly monotonic trend between $n_e$ and star formation rate, but the
KMOS$^{\rm 3D}$ galaxies have systematically higher $n_e$ than the SAMI
galaxies at fixed offset from the star-forming main sequence, suggesting a link
between the $n_e$ evolution and the evolving main sequence normalization. We
quantitatively test potential drivers of the density evolution and find that
$n_e$(rms) $\simeq{n_{H_2}}$, suggesting that the elevated $n_e$ in high-$z$ H
II regions could plausibly be the direct result of higher densities in the
parent molecular clouds. There is also tentative evidence that $n_e$ could be
influenced by the balance between stellar feedback, which drives the expansion
of H II regions, and the ambient pressure, which resists their expansion.
