  We extend the celebrated rigidity of the sharp first spectral gap under
$Ric\ge0$ to compact infinitesimally Hilbertian spaces with non-negative (weak,
also called synthetic) Ricci curvature and bounded (synthetic) dimension i.e.
to so-called compact $RCD(0,N)$ spaces; this is a category of metric measure
spaces which in particular includes (Ricci) non-negatively curved Riemannian
manifolds, Alexandrov spaces, Ricci limit spaces, Bakry-\'Emery manifolds along
with products, certain quotients and measured Gromov-Hausdorff limits of such
spaces. In precise terms, we show in such spaces, $\lambda =
\frac{\pi^{2}}{\mathrm{diam}^2}$ if and only if the space is one dimensional
with a constant density function. We use new techniques mixing Sobolev theory
and singular $1D$-localization which might also be of independent interest. As
a consequence of the rigidity in the singular setting, we also derive almost
rigidity results.
