«as per snell's law angle of refraction must be zero»
Snell's law assumes a homogeneous medium
Snell's law assumes a homogeneous medium (in which the refractive index is the same everywhere). Because of this homogeneity, all points of the medium on the surface become identical point sources of spherical wave fronts (Huygens' principle). In the figure, the flat front on the left reaches points $O_1$ and $O_2$ on the surface of the plate.
All point sources on the surface of a homogeneous medium have the same speed of light propagation (this is the speed of light $C$ in vacuum divided by the refractive index $n$ of the medium). Therefore, a flat front parallel to a flat homogeneous surface remains the same after passing through it (there is no refraction). If the medium is inhomogeneous (in the figure, the refractive index at the top is large $n_2$, and at the bottom is small $n_1$), spherical fronts from point sources will run into the medium at different speeds. Therefore, the plane touching them (a flat wave front) will no longer be parallel to the surface. It will bend towards it in those areas where the speed of light is less (the refractive index is greater), i.e. at the top of the picture.
Over some time $T$, the spherical front from the upper point $O_2$ will pass with a small speed $C_2$ (due to the large refractive index $n_2$) a small distance $O_2B_2= TC_2= TC/n_2$, and from the lower point $O_1$ - a large distance $O_1B_1= TC_1= TC/n_1$. The plane tangent to these spherical fronts (in the figure this is straight line $A_1A_2$, tangent to the circles with centers $O_1$ and $O_2$), forms an angle with the surface $O_1O_2$ approximately equal to angle $α$ in the right triangle $B_1B_2D_1$. This approximation is more accurate the smaller $α$, i.e. the smaller the difference between $n_2$ and $n_1$. In this approximation, we replace the tangent section $A_1A_2$ with the secant section $B_1B_2$ and obtain from the triangle $B_1B_2D_1$
$tg(α)= (D_1B_1/O_1O_2)= (|O_1B_1-O_2B_2|/h)= (TC/n_1-TC/n_2)/h= TC(1/n_1-1/n_2)/h$.
This plane gradually moves inside the plate and rotates relative to its surface.
Due to the linearity of the refractive index gradient, the radii of all spherical fronts with sources between points $O_1$ and $O_2$ will vary linearly on this segment. Therefore, the plane $A_1A_2$ will touch all these spherical fronts and thereby turn out to be the desired plane wave front inside the medium. If the gradient of the refractive index between points $O_1$ and $O_2$ is not linear, but convex, then the wave front will be distorted accordingly (it will be similar to focusing light in lenses).
But let's return to the case of a linear gradient. The approximate flat front $B_1B_2$ moves inside the plate and simultaneously rotates relative to its surface until its slowest upper point $B_2$ at speed $C_2$ passes the entire thickness $d$ of the plate to point $R_2$ in time $T_2= d/C_2= dn_2/C$. A spherical front will begin to emit from this point on the surface at this moment. But by this moment, the fastest bottom point of the front $B_1$ will not only have time to reach point $P_1$ on the surface, but also emit a spherical front, which will have time to reach some point $R_1$. The lower point $B_1$ will pass the entire thickness of the plate $d$ to point $P_1$ on the surface in time $T_1= d/C_1= dn_1/C$. At this moment, a spherical front will appear from point $P_1$, which in the remaining time $T_2-T_1$ will cover the distance
$P_1R_1= (T_2-T_1)C= (dn_2/C-dn_1/C)C= d(n_2-n_1)$.
As a result, a flat front will emerge from the surface, approximately coinciding with $R_1R_2$ (similar to what was for $A_1A_2$). From the right triangle $R_2R_1P_1$ we obtain
$tg(φ)= P_1R_1/h= d(n_2-n_1)/h$
Q.E.D.