In contrast to the water-poor planets of the inner Solar System, stochasticity during planetary formation1,2 and order-of-magnitude deviations in exoplanet volatile contents3 suggest that rocky worlds engulfed in thick volatile ice layers4,5 are the dominant family of terrestrial analogues6,7 among the extrasolar planet population. However, the distribution of compositionally Earth-like planets remains insufficiently constrained3, and it is not clear whether the Solar System is a statistical outlier or can be explained by more general planetary formation processes. Here we use numerical models of planet formation, evolution and interior structure to show that a planet's bulk water fraction and radius are anti-correlated with initial 26Al levels in the planetesimal-based accretion framework. The heat generated by this short-lived radionuclide rapidly dehydrates planetesimals8 before their accretion onto larger protoplanets and yields a system-wide correlation9,10 of planetary bulk water abundances, which, for instance, can explain the lack of a clear orbital trend in the water budgets of the TRAPPIST-1 planets11. Qualitatively, our models suggest two main scenarios for the formation of planetary systems: high-26Al systems, like our Solar System, form small, water-depleted planets, whereas those devoid of 26Al predominantly form ocean worlds. For planets of similar mass, the mean planetary transit radii of the ocean planet population can be up to about 10% larger than for planets from the 26Al-rich formation scenario.