I was playing around with a Hamiltonian model for the propagation of photons:
$$ H = c \sqrt{p \cdot p} + V(q) $$$$ H = c \sqrt{p \cdot p} + V(q) \tag{1}$$
which gives a meaningful set of equations of motion,
$$ \dot{q}_i = c \frac{p_i}{\sqrt{p \cdot p}} \quad \quad \dot{p}_i = - \frac{\partial V(q)}{\partial q_i} $$$$ \dot{q}_i = c \frac{p_i}{\sqrt{p \cdot p}} \quad \quad \dot{p}_i = - \frac{\partial V(q)}{\partial q_i}. \tag{2}$$
Notice that $\dot{q} \cdot \dot{q} = c^2$$$\dot{q} \cdot \dot{q} = c^2\tag{3}$$ always which is why I considered this as modeling the propagation of a massless particle.
However, this Hamiltonian has the following strange feature. If we perform a Legendre transformation to find an associated Lagrangian, $$ \mathcal{L} = p \cdot \dot{q} - H = c \frac{p \cdot p}{\sqrt{p \cdot p}} - \left( c \sqrt{p \cdot p} + V(q) \right) = - V(q) $$$$ \mathcal{L} = p \cdot \dot{q} - H = c \frac{p \cdot p}{\sqrt{p \cdot p}} - \left( c \sqrt{p \cdot p} + V(q) \right) = - V(q) \tag{4}$$ which is not dynamical since $\frac{\partial \mathcal{L}}{\partial \dot{q}} = 0$.
A similar problem arises if I consider a dual Lagrangian system in $q, \dot{q}$ variables and attempt to find a Hamiltonian by Legendre transformation: $$ \mathcal{L} = c \sqrt{\dot{q} \cdot \dot{q}} - V(q) $$$$ \mathcal{L} = c \sqrt{\dot{q} \cdot \dot{q}} - V(q) \tag{5}$$ then we get well-defined Euler-Lagrange equations: $$ \frac{\mathrm{d}}{\mathrm{d} t} \left( c \frac{\dot{q}_i}{\sqrt{\dot{q}_i \cdot \dot{q}_i}} \right) = - \frac{\partial V(q)}{\partial q_i} $$$$ \frac{\mathrm{d}}{\mathrm{d} t} \left( c \frac{\dot{q}_i}{\sqrt{\dot{q}_i \cdot \dot{q}_i}} \right) = - \frac{\partial V(q)}{\partial q_i}\tag{6} $$ which becomes: $$ (\dot{q} \cdot \dot{q}) \ddot{q}_i - (\dot{q} \cdot \ddot{q}) \dot{q}_i + (\dot{q} \cdot \dot{q})^{3/2} \frac{\partial V(q)}{\partial q_i} = 0 $$$$ (\dot{q} \cdot \dot{q}) \ddot{q}_i - (\dot{q} \cdot \ddot{q}) \dot{q}_i + (\dot{q} \cdot \dot{q})^{3/2} \frac{\partial V(q)}{\partial q_i} = 0.\tag{7} $$ However, if we try to find an associated Hamiltonian, $$ H = p \cdot \dot{q} - \mathcal{L} = c \frac{\dot{q} \cdot \dot{q}}{\sqrt{\dot{q} \cdot \dot{q}}} - \left( c \sqrt{\dot{q} \cdot \dot{q}} - V(q) \right) = V(q) $$$$ H = p \cdot \dot{q} - \mathcal{L} = c \frac{\dot{q} \cdot \dot{q}}{\sqrt{\dot{q} \cdot \dot{q}}} - \left( c \sqrt{\dot{q} \cdot \dot{q}} - V(q) \right) = V(q) \tag{8}$$ which is again non-dynamical.
What is going on here? Is there an interesting reason that these systems should not admit Lagrangian/Hamiltonian descriptions? In general, when should I expect the Legendre transformation to give me a well-behaved system that reproduces the physics I started with?