Your equation of motion is not correct, you were already given the right one. But indeed your equation is trivially satisfied. That's because the Lagrangian itself is a total derivative, then the action

$$L[q]=-\int_a^b\frac{d}{dt}\cos(q(t))\mathrm{d}t=cte.$$

does not depend on the path $q(t)$ but on the endpoints, which you held fixed. That is, as a variational problem, it is trivial as any Lagrangian having the form $\mathcal{L}[q,t]=\dot{f}(q(t))$. Actually, Lagrangians are not uniquelly, but defined up to those kind of terms.

In higher dimensions the Lagrangians that mimic that in your question are