  The dust-to-stellar mass ratio ($M_{\rm dust}$/$M_{\rm \star}$) is a crucial
yet poorly constrained quantity to understand the production mechanisms of
dust, metals and stars in galaxy evolution. In this work we explore and
interpret the nature of $M_{\rm dust}$/$M_{\rm \star}$ in 300 massive
($M_{\star}>10^{10}M_{\odot}$), dusty star-forming galaxies detected with ALMA
up to $z\approx5$. We find that $M_{\rm dust}$/$M_{\rm \star}$ evolves with
redshift, stellar mass, specific SFR and integrated dust size, differently for
main sequence and starburst galaxies. In both galaxy populations $M_{\rm
dust}$/$M_{\rm \star}$ rises until $z\sim2$ followed by a roughly flat trend
towards higher redshifts. We show that the inverse relation between $M_{\rm
dust}$/$M_{\rm \star}$ and $M_{\star}$ holds up to $z\approx5$ and can be
interpreted as an evolutionary transition from early to late starburst phases.
We demonstrate that $M_{\rm dust}$/$M_{\rm \star}$ in starbursts mirrors the
increase in molecular gas fraction with redshift, and is enhanced in objects
with the most compact dusty star-formation. The state-of-the-art cosmological
simulation SIMBA broadly matches the evolution of $M_{\rm dust}$/$M_{\rm
\star}$ in main sequence galaxies, but underestimates it in starbursts. The
latter is found to be linked to lower gas-phase metallicities and longer dust
growth timescales relative to data. Our data are well reproduced by analytical
model that includes recipes for rapid metal enrichment, strongly suggesting
that high $M_{\rm dust}$/$M_{\rm \star}$ is due to fast grain growth in metal
enriched ISM. Our work highlights multifold benefits of using $M_{\rm
dust}$/$M_{\rm \star}$ as a diagnostic tool for: (1) separating main sequence
and starburst galaxies until $z\sim5$; (2) probing the evolutionary phases of
dusty galaxies, and (3) refining the treatment of dust life cycle in
simulations.
