For many massive compact galaxies, their dynamical masses (Mdyn∝σ2re) are lower than their stellar masses (M⋆). We analyse the unphysical mass discrepancy M⋆/Mdyn>1 on a stellar-mass-selected sample of early-type galaxies (M⋆≳1011M⊙) at redshifts z∼0.2 to z∼1.1. We build stacked spectra for bins of redshift, size and stellar mass, obtain velocity dispersions, and infer dynamical masses using the virial relation Mdyn≡Kσe2re/G with K=5.0; this assumes homology between our galaxies and nearby massive ellipticals. Our sample is completed using literature data, including individual objects up to z∼2.5 and a large local reference sample from the Sloan Digital Sky Survey (SDSS). We find that, at all redshifts, the discrepancy between M⋆ and Mdyn grows as galaxies depart from the present-day relation between stellar mass and size: the more compact a galaxy, the larger its M⋆/Mdyn. Current uncertainties in stellar masses cannot account for values of M⋆/Mdyn above 1. Our results suggest that the homology hypothesis contained in the Mdyn formula above breaks down for compact galaxies. We provide an approximation to the virial coefficient K∼6.0[re/(3.185kpc)]−0.81[M⋆/(1011M⊙)]0.45, which solves the mass discrepancy problem. A rough approximation to the dynamical mass is given by Mdyn∼[σe/(200kms−1)]3.6[re/(3kpc)]0.352.1×1011M⊙.