I'm trying to understand something with the lagrangian and the hamiltonian formalisms in relativity theory, and why the following result cannot be the same in classical (non-relativistic) mechanics. There's something missing or badly defined in my reasoning, and I don't see what yet.
Consider a system of "particles", of generalized coordinates $q^i(t)$ in some reference frame. The action of the system is defined as the following integral : \begin{equation}\tag{1} S = \int_{t_1}^{t_2} L(q^i, \dot{q}^i) \, dt. \end{equation} The hamiltonian of the system is defined as this (summation is implied on the repeated indices) : \begin{equation}\tag{2} H = \dot{q}^i \, \frac{\partial L}{\partial \dot{q}^i} - L. \end{equation} Now consider a change of parametrization in integral (1) ; $dt = \theta \, ds$, where $s$ is a new integration variable and $\theta(s)$ is an arbitrary function that could be considered as a new dynamical variable (there's something missing in my interpretation, and I need to find what is "wrong" here). The action is now this (the prime is the derivative with respect to $s$. Notice the change of limits, on this integral) : \begin{equation}\tag{3} S = \int_{s_1}^{s_2} L(q^i, \frac{q^{i \, \prime}}{\theta}) \; \theta \; ds. \end{equation} So the new lagrangian is \begin{equation}\tag{4} \tilde{L} = L(q^i, \frac{q^{i \, \prime}}{\theta}) \; \theta. \end{equation} Now, if $\theta$ is considered as a dynamical variable, we can apply the Euler-Lagrange to this new lagrangian: \begin{equation}\tag{5} \frac{d}{d s} \Big( \frac{\partial \tilde{L}}{\partial \, \theta^{\, \prime}} \Big) - \frac{\partial \tilde{L}}{\partial \, \theta} = 0. \end{equation} Since there is no $\theta^{\, \prime}$ in $\tilde{L}$, the first part is 0. After some simple algebra, the second part implies that the hamiltonian (2) should be 0 ! \begin{equation}\tag{6} H \equiv 0. \end{equation}
So my questions are these:
Is there something wrong in the previous reasoning? Or what implicit assumptions am I missing? Where is relativity in this?
If the reasoning is valid, why can't we apply the result to any classical lagrangian, which would give non-sense?
Of course, I know that the hamiltonian of free relativistic particles isn't 0! But I also know that $H = 0$ is a well known property of systems which have an action with parametrization independence. I'm missing some parts related to this constraint and I don't see what yet. I need help to disentangle this subject.