We measure energy-dependent time delays of ~20-200 keV hard X-ray (HXR) emission from 78 flares observed simultaneously with the Compton Gamma Ray Observatory and Yohkoh. Fast time structures (<~1 s) are filtered out, because their time delays have been identified in terms of electron time-of-flight (TOF) differences from directly precipitating electrons (Aschwanden et al.). For the smooth HXR flux, we find systematic time delays in the range of τS = t50 keV-t200 keV ~ -(1 ... 10) s, with a sign opposite to TOF delays, i.e., the high-energy HXRs lag the low-energy HXRs.We interpret these time delays of the smooth HXR flux in terms of electron trapping, and we fitted a model of the collisional deflection time tDefl(E)~E3/2n-1e to the observed HXR delays in order to infer electron densities nTrape in the trap. Independently, we determine the electron density nSXRe in flare loops from soft X-ray (SXR) peak emission measures EM= n2edh, using loop width (w) measurements to estimate the column depth dh ~ w. Comparing the two independent density measurements in HXR and SXR, we find a mean ratio of qe=nTrape/nSXRe~1, with a relatively small scatter by a factor of ~2. Generally, it is likely that the SXR-bright flare loops have a higher density than the trapping regions (when qe < 1), but they also are subject to filling factors less than unity (when qe > 1). Our measurements provide comprehensive evidence that electron trapping in solar flares is governed in the weak-diffusion limit, i.e., that the trapping time corresponds to the collisional deflection time, while pitch-angle scattering by resonant waves seems not to be dominant in the 20-200 keV energy range. The measurements do not support a second-step acceleration scenario for energies <=200 keV.