Why do we treat velocity and coordinates as independent variables until the very end, where we then assume the dependence of velocity on coordinates via a time derivative? That is, let the Lagrangian of a given system be simply
$$\mathcal L=\frac12mv^2$$
Now, plugging this into the Euler-Lagrange equation, we get
$$\frac\partial{\partial x}\mathcal L-\frac d{dt}\frac\partial{\partial v}\mathcal L=0$$
$$\frac12m\bigg(\frac\partial{\partial x}v^2\bigg)-\frac12m\bigg(\frac d{dt}\frac\partial{\partial v}v^2\bigg)=0\tag1$$
$$\frac d{dt}v=0\rightarrow v= \text{constant wrt time}$$
So far, this calculation has shown that in phase space, $v$ is a constant in time.
Now, how can we justify the identification $v=dx/dt$ when we initially treated $v$ as independent and neglected this definition in the first term of (1)?