In General Relativity (and special too) the Lagrangian for a particle of mass $m$ in the absence of forces other than gravity is
$$L=m\sqrt{g_{\mu\nu}U^\mu U^\nu}$$
where $U^\mu$ is the four-velocity. In that case we can derive the momentum $p_\mu$ by
$$p_\mu=\dfrac{\partial L}{\partial U^\mu}=\dfrac{\partial}{\partial U^\mu}m\sqrt{g_{\alpha\beta}U^\alpha U^\beta}$$
$$p_\mu=\dfrac{mg_{\alpha\beta}}{2\sqrt{g_{\alpha\beta}U^\alpha U^\beta}}\left(\delta^\alpha_\mu U^\beta+\delta^\beta_\mu U^\alpha\right)=\dfrac{mg_{\mu \alpha}U^\alpha}{\sqrt{g_{\alpha\beta} U^\alpha U^\beta}}$$
If we parametrize the worldline by proper time $\tau$ then $L(\gamma(\tau),\gamma'(\tau))=m$ and we get of the square root on the denominator which is just $1$. Then
$$p_\mu= m g_{\mu\alpha}U^\alpha,$$
and these are the components of a covector. This directly leads to the momentum four-vector
$$p^\mu= m U^\mu.$$
Everything works here. Now I want to compute the energy. Well the Hamiltonian as always should be
$$H=p_\mu U^\mu-m\sqrt{g_{\mu\nu}U^\mu U^\nu}=m g_{\mu\nu}U^\mu U^\nu-m\sqrt{g_{\mu \nu}U^\mu U^\nu}.$$
But if things are parametrized by propertime, when we compute $H$ on the path, that is $H(\gamma(\tau),\gamma'(\tau))$ we get zero!
What I expected was to get $H = p^0$.
What am I doing wrong here? Why am I getting zero?