Considering what Greg Graviton wrote, I'll write out the derivation and see if I can make sense of it.

$$ S = \int_{t_1}^{t_2} L(q, \dot q, t)\, \mathrm{d}t $$

where S is the action and L the Lagrangian. We vary the path and find the extremum of the action:

$$ \delta S = \int_{t_1}^{t_2} \left({\partial L \over \partial q}\delta q + {\partial L \over \partial \dot q}\delta \dot q\right) \,\mathrm{d}t = 0\,. $$

Here, q and $\dot q$ are varied independently. But then in the next step we use this identity,

$$ \delta \dot q = {\mathrm{d} \over \mathrm{d}t} \delta q. $$

And here is where the relationship between q and $\dot q$ enters the picture. I think that what is happening here is that q and $\dot q$ are treated as independent initially, but then the independence is removed by the identity.

$$ \delta S = \int_{t_1}^{t_2} \left({\partial L \over \partial q}\delta q + {\partial L \over \partial \dot q}{d \over \mathrm{d}t} \delta q\right) \,\mathrm{d}t = 0 $$

And then follows the rest of the derivation. We integrate the second term by parts:

$$ \delta S = \left[ {\partial L \over \partial \dot q}\delta q\right]_{t_1}^{t_2} + \int_{t_1}^{t_2} \left({\partial L \over \partial q} - {d \over dt}{\partial L \over \partial \dot q}\right)\delta q\, \mathrm{d}t = 0\,, $$

and the bracketed expression is zero because the endpoints are held fixed. And then we can pull out the Euler-Lagrange equation:

$$ {\partial L \over \partial q} - {\mathrm{d} \over \mathrm{d}t}{\partial L \over \partial \dot q} = 0\,. $$

Now it makes more sense to me. You start by treating the variables as independent but then remove the independence by imposing a condition *during* the derivation.

I think that makes sense. I expect in general other problems can be treated the same way.

(I copied the above equations from *Mechanics* by Landau and Lifshitz.)