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
$\mathcal{L}[\phi]=\mathrm{d}{\phi}$
for $\phi$ a (dim$M-1$)-form, so that, by Stokes theorem:
$ S=\int_M\mathcal{L} =\int_M\mathrm{d}\phi = \int_{\partial M} \phi $
If $M$ is boundaryless or $\phi$ is compactly supported, this term has trivial equations of motion $-$ no dynamics.