Consider a Lagrangian $L(q, \dot{q}, t)$ for a single particle. The variation of the Lagrangian is given by:
$$\delta L= \frac{\partial L}{\partial q}\delta q + \frac{\partial L}{\partial \dot q}\delta \dot q\tag1$$
When using Hamilton's Principle ($\delta S = 0$):
$$\delta S = \delta \left[ \int L(q, \dot q, t) dt \right] =\int \delta [L(q, \dot q, t)] dt = 0\tag2$$
and the right-hand side of equation (1),
$$\int \left( \frac{\partial L}{\partial q}\delta q + \frac{\partial L}{\partial \dot q}\delta \dot q \right)dt = 0\tag3$$
We then swap the order of time derivative and variation on the second term in the integrand to get:
$$\int \left( \frac{\partial L}{\partial q}\delta q + \frac{\partial L}{\partial \dot q}\frac{d}{dt}(\delta q) \right)dt = 0\tag4$$
Where we then integrate by parts and get the E-L equations.
My question is how do we justify trading the order of time differentiation and the variation on q? What is the argument for the identity $\delta \dot q = \frac{d}{dt}(\delta q)$, i.e. to rewrite equation (3) as equation (4).