Differentiation of the law of cosines $$s^2=R^2+r^2-2Rr\cos(\theta)$$
differentiated to give
$$2s\text ds=2Rr\sin(\theta)\text d\theta$$
$$\sin\theta\text d\theta=\frac{s\text ds}{Rr}$$
I found this differentiation in a site that was explaining the gravitational force inside a hollow sphere and it used these differentiation as a proof.
I don't understand that why does this work, when its differentiating with respect to different values.
 A: This method is named Implicit Differentiation which is nothing more than a frequently-used application of the Chain Rule, which states that:
$$\frac{dy}{dx} = \frac{dy}{du} \cdot \frac{du}{dx}$$
We can now take some implicit function (a function containing multiple variables, intermixed), such as:
$$2y^3 = x^2 + \sin(2y)$$
and differentiate implicitly, w.r.t $x$, to give:
$$6y^2\frac{dy}{dx} = 2x + 2\cos(2y)\frac{dy}{dx}$$
This works because when we need to differentiate a function of $y$ w.r.t $x$, we can use the Chain Rule. This can be seen more explicitly by letting, $u = 2y^3$ and $v = \sin(2y)$.
Now the equation becomes:
$$u = x^2 + v$$
and we can differentiate $u$ and $v$ w.r.t $x$ via the Chain Rule:
$$\frac{du}{dx} = \frac{du}{dy}\cdot\frac{dy}{dx} = 6y^2\frac{dy}{dx}$$
Similarly,
$$\frac{dv}{dx} = \frac{dv}{dy}\cdot\frac{dy}{dx} = 2\cos(2y)\frac{dy}{dx}$$
Hence putting those two together, we get the answer we have before.

Now to apply the same method to your example.
$$s^2 = R^2 + r^2 - 2Rr\cos(\theta)$$
It is clear from the extract you posted that the variables here are $s$ and $\theta$ whereas $r$ and $R$ are constants.
Let us differentiate w.r.t $\theta$, giving:
$$2s\frac{ds}{d\theta} = 2Rr\sin(\theta)$$
We can now multiply through by the differential $d\theta$ to give your result:
$$2sds = 2Rr\sin(\theta)d\theta$$
It should be obvious that if we had differentiated w.r.t $s$, we would have a $\frac{d\theta}{ds}$ on the RHS and the $ds$ would be multiplied across to the LHS giving the same result.
A: I'm not really sure if you are asking for a proof of the fact that the gravitational field inside a hollow shell of material of mass $M$ is zero or if you are asking about why the final equation you quote in your question is true. I assume you are asking about the equation. To get the result you could take the square root of both sides and then differentiate with respect to $\theta$ to get the final result, but this leaves more room for making errors when doing the differentiation. Taking the square root of both sides 
in
$$
s^2 = R^2+r^2-2Rr\cos\theta
$$
gives
$$
s = \sqrt{R^2 +r^2 - 2Rr\cos\theta}\,.
$$
Differentiating both sides with respect to $\theta$ gives 
$$
\frac{ds}{d\theta} = \frac{1}{2}\frac{-2Rr\dfrac{d(\cos\theta)}{d\theta}}{\sqrt{R^2+r^2-2Rr\cos\theta}} \,,
$$
which can be written as
$$
\frac{ds}{d\theta} = \frac{1}{2}\frac{-2Rr(-\sin\theta)}{s} = \frac{Rr\sin\theta}{s}\,.
$$
Therefore, 
$$
\frac{ds}{d\theta} = \frac{Rr\sin\theta}{s}\,.
$$
This can be rearranged to give
$$
\sin\theta\, d\theta = \frac{sds}{Rr}\,.
$$
As the user David White mentions in his comment the author of the book uses implicit differentiation, where as taking the square root of both sides gives $s$ as a function of $\theta\,.$
