Given the Hamiltonian $$H=\frac{1}{2}m (\dot{r}^2 +(r\dot{\theta})^{2}) - \frac{k}{r},\tag{1}$$
And the Lagrangian $$L=\frac{1}{2}m (\dot{r}^2 +(r\dot{\theta})^{2}) + \frac{k}{r},\tag{2}$$
its generalized momentum of $\bf r$:
$${p_{r}} = \frac{\partial L}{\partial \dot{r}} =m\dot{r}$$
To obtain the Hamiltonian equation of motion:
For $\bf{r}$: $$\frac{\partial H}{\partial r} = -\dot{p_{r}} = mr\dot{\theta^2} + \frac{k}{r^2} = \frac{p_{\theta}^2}{mr^3}+\frac{k}{r^2} $$
However, if we substitute the generalized momentum to Hamiltonian at the beginning
$$\implies H =\frac{1}{2}\left(\frac{p_{r}^2}{m}+ \frac{p_{\theta}^2}{mr^2}\right) -\frac{k}{r}$$
Then we differentiate Hamiltonian with respect to $\bf{r}$:
$$\frac{\partial H}{\partial r}= -\dot{p_{r}}= -\frac{p_{\theta}^2}{mr^3} + \frac{k}{r^2}$$
Why do the two different methods have two answers? Shouldn't they be the same equation? Because we are using exactly the same way to obtain the equation of motion? The only different is we substitute the generalized momentum at the the answer and another at the beginning.