Longitudinal dynamics of extreme plasma-based compression of electron beams