In a medium stratified in parallel planes, translate the ray along those planes and nothing changes. That symmetry makes the component of the wave vector along the planes conserved, which is exactly μ sinθ = constant with θ measured from the normal to the layers. Snell's law is the two-layer case; a stack of 100 slices telescopes to the same statement (A); a continuous profile is the limit of infinitely many infinitely thin slices, so the sum becomes an integral (B, C).
Rays always bend towards the region of larger μ (slower light). When the layers instead run along the ray, as in the GRIN lens (D), the invariant is silent and you work with optical path length instead.
Every case here uses the same numerical engine: N flat slices with Snell at each face. Raise N and watch the polyline collapse onto the exact curve.