  Abundance matching studies have shown that the average relationship between
galaxy radius and dark matter halo virial radius remains nearly constant over
many orders of magnitude in halo mass, and over cosmic time since about $z=3$.
In this work, we investigate the predicted relationship between galaxy radius
$r_{e}$ and halo virial radius $R_{\rm h}$ in the numerical hydrodynamical
simulations Illustris and IllustrisTNG from $z\sim 0$--3, and compare with the
results from the abundance matching studies. We find that Illustris predicts
much higher $r_e/R_{\rm h}$ values than the constraints obtained by abundance
matching, at all redshifts, as well as a stronger dependence on halo mass. In
contrast, IllustrisTNG shows very good agreement with the abundance matching
constraints. In addition, at high redshift it predicts a strong dependence of
$r_e/R_{\rm h}$ on halo mass on mass scales below those that are probed by
existing observations. We present the predicted $r_e/R_{\rm h}$ relations from
Illustris and IllustrisTNG for galaxies divided into star-forming and quiescent
samples, and quantify the scatter in $r_e/R_{\rm h}$ for both simulations.
Further, we investigate whether this scatter arises from the dispersion in halo
spin parameter and find no significant correlation between $r_e/R_{\rm h}$ and
halo spin. We investigate the paths in $r_e/R_{\rm h}$ traced by individual
haloes over cosmic time, and find that most haloes oscillate around the median
$r_e/R_{\rm h}$ relation over their formation history.
