In a medium with varying refractive index $n(x,y)$ the differential equations for the ray curve point $(x,y)$ are as follows1:
$$\begin{align}
\frac{\partial n}{\partial x}&=\frac{\mathrm d}{\mathrm{d}s}\left(n\frac{\mathrm{d} x}{\mathrm{d} s}\right),\\
\frac{\partial n}{\partial y}&=\frac{\mathrm d}{\mathrm{d}s}\left(n\frac{\mathrm{d} y}{\mathrm{d} s}\right),
\end{align}$$
where the parameter $s$ is the path along the ray.
If we take the refractive index to vary along $y$ but remain constant along $x$, e.g.
$$n(x,y)=1+ay,$$
and then try to substitute what we think to be the solution for $y$-coordinate of the ray,
$$y(s)=y_0,$$
we'll find that the second equation reads
$$a=0.$$
In other words, this solution is only valid for vacuum, not for any linear-index material. Similar results will be for quadratic profile of refractive index. Thus, the ray must curve, not propagate in straight line.
If you try instead $n(x,y)$ piecewise-constant in $y$, you'll find that rays can indeed propagate along the constant-index strips, so this doesn't contradict Snell's law. It's just that Snell's law doesn't work at the boundary, and in the limit of smooth refractive index profile all points will be boundaries.
References
1: Kevin Brown, "Reflections on Relativity", §8.4 "Refractions on Relativity". Relevant derivation is quoted in my answer to How to calculate the refracted light path when refraction index continuously increasing?