To derive Lagrange equation of motion, which are
$$\frac d {dt} \frac {\partial L} {\partial \dot q}-\frac {\partial L} {\partial q} =0$$
we need the virtual work of constraint to be zero , as is said by Goldstein while deriving the equations
We again restrict ourselves to systems for which the virtual work of the forces of constraint vanishes and therefore obtain $$ \sum_{i}\left(\mathbf{F}_{i}^{(a)}-\dot{\mathbf{p}}_{i}\right) \cdot \delta \mathbf{r}_{i}=0 $$ which is often called d'Alembert's principle...
One of the examples using Lagrange equations is of a elastic pendulum as shown
But the virtual displacement isn't perpendicular to the constraint force (spring force) here, so the virtual work of the constraint will not be zero and hence we cannot apply the Lagrange equations.
Why then do we solve this problem using the Lagrange equations?