Dividing by $dP$ is not legal - it's a case of Physicists being "sloppy". What is really happening here is that $S$ and $P$ provide a coordinate system of this manifold, and $T$ and $P$ also provide a coordinate system. Their respective dual bases of the tangent space are
$$\left(\frac{\partial}{\partial S}\right)_P, \left(\frac{\partial}{\partial P}\right)_S \quad\text{and}\quad \left(\frac{\partial}{\partial T}\right)_P, \left(\frac{\partial}{\partial P}\right)_T$$
Now $d H = \left(\frac{\partial H}{\partial T}\right)_P d T + \left(\frac{\partial H}{\partial P}\right)_T d P = T \,dS + V \,dP = T \left( \left(\frac{\partial S}{\partial T}\right)_P d T + \left(\frac{\partial S}{\partial P}\right)_T d P\right) + V \, d P$
Since $d T$ and $d P$ are linearly independent your equation follows.