We describe the general mechanism of tetragonal distortion in Heusler compounds X2YZ. From 286 compounds studied using density-functional theory, 62% are found to be tetragonal at zero temperature. Such a large share of compounds with tetragonal distortions can be explained by the peak-and-valley character of the density of states (DOS) of these compounds in the cubic phase (arising from localized d bands and van Hove singularities) in conjunction with a smooth shift of peaky DOS structure relative to the Fermi energy, EF, when valence electrons are added to the system. A shift of the DOS in the Y or Z series leads to an alternation of stable and nonstable cubic phases that depends on the value of the DOS at EF in the cubic phase. Groups of compounds with a large share of tetragonal distortions are identified and explained.