We will show one inclusion, and conclude with a dimension argument. I assume that we already know that $f^{-1}(S)$ is a submanifold, and I will use the word "path", but try to very emphasize on the derivation meaning.
- The inclusion $T_p(f^{-1}(S))\subset (df_p)^{-1}(T_{f(p)}S)$:
Take any tangent vector $V\in T_p(f^{-1}(S))$. You know that you can always find a smooth path $\gamma:]-\varepsilon,\varepsilon[\to f^{-1}(S)$ such that $\gamma(0)=p$ and $\gamma'(0)=V$. Two little remarks:
$\gamma'(0)$ is by definition the derivation $d\gamma_0(\frac{d}{dt}|_0)$, where $\frac{d}{dt}|_0$ is the usual derivation on $\mathcal{C}^{\infty}_0(\mathbb{R})$ given by $\frac{d}{dt}|_0\,f:=f'(0)$ ;
Here I will canonically identify the tangent space of a submanifold $V$ as a vectorial subspace of the tangent space of an ambient manifold $W$ with the canonical inclusion $di_p:T_pV\to T_pW$, where $i:V\to W$ is the inclusion.
Then we have that
$$df_p(V)=df_p(\gamma'(0))=df_p(d\gamma_0(\frac{d}{dt}))=d(f\circ\gamma)_0(\frac{d}{dt})=\tilde\gamma'(0)=\tilde V,$$
with $\tilde{\gamma}:=f\circ\gamma$ which is a smooth path such that $Im(\tilde\gamma)\subset S$, so $\tilde V\in T_{f(p)}S$, $V\in (df_p)^{-1}(T_{f(p)}S)$, and we get our inclusion.
First, $\dim f^{-1}(S)=\dim M-\mathrm{codim}_NS$, so $\dim T_p(f^{-1}(S))=\dim M-\mathrm{codim}_NS$.
Then, $\dim\,(df_p)^{-1}({T_f(p)}S)\overset{(\star)}{=}\dim \ker (df_p)+\dim df_p(T_pM)\cap T_{f(p)}S$ (classic exercise: if $L:E\to F$ is a linear morphism and $G$ a linear subspace of $F$, apply the rank formula to $L|_{L^{-1}(G)}:L^{-1}(G)\to G$). By transversality, we know that
$$df_p(T_pM)+T_{f(p)}S=T_{f(p)}N,$$
so by Grassmann formula:
$$\dim(df_p(T_pM)\cap T_{f(p)}S)=\dim df_p(T_pM)+\dim {T_f(p)} S-\dim T_{f(p)}N.$$
In $(\star)$, it gives
\begin{align}
\dim\,(df_p)^{-1}({T_f(p)}S)&=\dim \ker (df_p)+\dim df_p(T_pM)+\dim {T_f(p)} S-\dim T_{f(p)}N\\
&=\dim M - \mathrm{codim}_NS.
\end{align}
By inclusion and equality of dimensions, we can conclude that these are the same vector spaces.