We rigorously justify the bilayer shallow-water system as an approximation to the hydrostatic Euler equations in situations where the flow is density-stratified with close-to-piecewise constant density profiles, and close-to-columnar velocity profiles. Our theory accommodates with continuous stratification, so that admissible deviations from bilayer profiles are not pointwise small. This leads us to define refined approximate solutions that are able to describe at first order the flow in the pycnocline. Because the hydrostatic Euler equations are not known to enjoy suitable stability estimates, we rely on thickness-diffusivity contributions proposed by Gent and McWilliams. Our strategy also applies to one-layer and multilayer frameworks.