How is a Hamiltonian constructed from a Lagrangian with a Legendre transform
The fact that $p = \large \frac{\partial L}{\partial \dot{q}} = 0$ introduces a problem in the equivalence between Lagrangian and Hamiltonian representations.
The idea is that the Hamiltonian representation plus the constraint $p = 0$ is equivalent to the Lagrangian representation
The Lagrangian $L$ is a function of $q$ and $\dot q$, that is $L(q, \dot q)$
If we work with the Lagrangian, we will apply the Euler-Lagrange equations which are :
$$\frac{\partial L}{\partial q} = \frac{d}{dt} \left(\frac{\partial L}{\partial \dot{q}}\right)$$
Because $\large \frac{\partial L}{\partial \dot{q}} = 0$, the equation is simply $\large \frac{\partial L}{\partial q} = 0$, that is $ \frac{1}{q} - 2\lambda = 0$, so $q = \frac{1}{2 \lambda}$
Now try to work with the Hamiltonian.
The Hamiltonian $H$ is a function of $q$ and $p$, that is $H(q, p)$
The link between the two is the Legendre transformation :
$$H=\dot{q}\frac{\partial L}{\partial \dot{q}}-L$$
Because your Lagrangian does not depends of $\dot q$, then $p = \frac{\partial L}{\partial \dot{q}} = 0$, and so :
$$H(q, p) = - L(q, \dot q) = - \ln(q) + (2q-10)\lambda$$
From this hamiltonian, you get the equations of movement :
$$\dot q = \frac{\partial H}{\partial p} ~,~\dot p = - \frac{\partial H}{\partial q}$$ So we have :
$$\dot q = 0~,~\dot p = \frac{1}{q} - 2\lambda \tag{1}$$
From this, we cannot recover the equation obtained from Euler-Lagrange equations, we have to add the constraint $p = 0$.
If $p = 0$, it means that $\dot p = 0$, and so :
$$q = \frac{1}{2 \lambda}\tag{2}$$
This is coherent with the fact that $\dot q = 0$