Compact ellipticals (cEs) are outliers from the scaling relations of early-type galaxies, particularly the mass-metallicity relation which is an important outcome of feedback. The formation of such low-mass, but metal-rich and compact, objects is a long-standing puzzle. Using a pair of high-resolution N-body+gas simulations, we investigate the evolution of a gas-rich low-mass galaxy on a highly radial orbit around a massive host galaxy. As the infalling low-mass galaxy passes through the hosts corona at supersonic speeds, its diffuse gas outskirts are stripped by ram pressure, as expected. However, the compactness increases rapidly because of bursty star formation in the gas tidally driven to the centre. The metal-rich gas produced by supernovae and stellar winds is confined by the ram pressure from the surrounding environment, leading to subsequent generations of stars being more metal-rich. After the gas is depleted, tidal interactions enhance the metallicity further via the stripping of weakly bound, old, and metal-poor stars, while the size of the satellite is changed only modestly. The outcome is a metal-rich cE that is consistent with observations. These results argue that classical cEs are neither the stripped remnants of much more massive galaxies nor the merger remnants of normal dwarfs. We present observable predictions that can be used to test our model.