When you compute a partial derivative in this situation, you need to have in mind which variables you are considering to be the independent variables and which are dependent.
A useful notation
often used in physics is
$$ \left( \frac{\partial x}{\partial y} \right)_{z,w} $$
to indicate the partial derivative of $x$ with respect to $y$ with $z$ and $w$ held constant (i.e. considering $x$ as a function of the independent variables $y, z, w$).
In the first instance, you are taking $r$ and $\theta$ as the
independent variables, and then it is true that
$$ \dfrac{\partial x}{\partial r} =\left(\dfrac{ \partial x}{\partial r}\right)_\theta = \cos(\theta)$$
In the second case, you have
$$ \dfrac{\partial r}{\partial x} = \left(\dfrac{ \partial r}{\partial x}\right)_y = \cos(\theta)$$
and there's no contradiction, because different variables are being held constant.
[EDIT] About the coincidence:
In general suppose you have
$ x = f(z,w)$ and $y = g(z,w)$. What must be true to make $\left(\dfrac{\partial x}{\partial z}\right)_w = \left(\dfrac{\partial z}{\partial x}\right)_y$?
It turns out that the condition is $$\dfrac{\partial f}{\partial z} = \dfrac{\dfrac{\partial g}{\partial w}}{\dfrac{\partial f}{\partial z} \dfrac{\partial g}{\partial w} - \dfrac{\partial f}{\partial w} \dfrac{\partial g}{\partial z}}$$
In the case at hand, this works out because of $\cos^2 + \sin^2 = 1$.
[EDIT]
This can be obtained by writing
$$ \eqalign{ dx &= \dfrac{\partial f}{\partial z}\; dz + \dfrac{\partial f}{\partial w}\; dw\cr
dy &= \dfrac{\partial g}{\partial z}\; dz + \dfrac{\partial g}{\partial w}\; dw}$$
With $w$ fixed, so $dw = 0$, you get of course
$$ \left( \dfrac{\partial x}{\partial z}\right)_w = \dfrac{\partial f}{\partial z} $$
But with $y$ fixed, you want $dy = 0$ so $$dw = - \dfrac{\dfrac{\partial g}{\partial z}}{\dfrac{\partial g}{\partial w}} \; dz $$
and then
$$ \left(\dfrac{\partial z}{\partial x} \right)_y = \dfrac{dz}{\dfrac{\partial f}{\partial z}\; dz + \dfrac{\partial f}{\partial w}\; dw} =
\dfrac{\dfrac{\partial g}{\partial w}}{\dfrac{\partial f}{\partial z} \dfrac{\partial g}{\partial w} - \dfrac{\partial f}{\partial w} \dfrac{\partial g}{\partial z}}$$