binbagsss said:
in classical mechanics you tend to vary with respect to time
Not really. You vary with respect to the "free variable"--the thing that the Lagrangian is a function of, and that changes from one path to another, but is held fixed at each endpoint. That is usually not going to be time.
For example, suppose we want to find the trajectory in Newtonian gravity that minimizes the action for a freely falling object. The action is the integral of kinetic minus potential energy, so we have (for the case of an object near the Earth's surface so ##g## can be assumed to be constant)
$$
S = \int L dt = \int_{t_0}^{t_1} \left[ \frac{1}{2} m \left( \frac{dh}{dt} \right)^2 - m g h \right] dt
$$
Notice that the time is part of the definition of the endpoints: the object is defined to start and end at a given value of ##h## (usually taken to be ##h = 0##) at given times ##t_0## and ##t_1##. So whatever we are going to vary with respect to, it can't be with respect to time.
What we actually vary with respect to can be seen by looking at the Euler-Lagrange equation, which for a general one-dimensional problem is
$$
\frac{d}{dt} \frac{\delta L}{\delta \dot{q}} = \frac{\delta L}{\delta q}
$$
where ##L## is the Lagrangian and ##q## is the generalized coordinate. In our particular case, ##q = h##--the generalized coordinate is height, and ##\dot{q} = dh / dt##, the velocity. So the Euler-Lagrange equation becomes
$$
\frac{d}{dt} \frac{\delta L}{\delta \dot{h}} = \frac{\delta L}{\delta h}
$$
If we use the ##L## we have above, we have ##\delta L / \delta \dot{h} = m \left( dh / dt \right)## and ##\delta L / \delta h = - m g##, which gives (canceling the ##m## from both sides)
$$
\frac{d}{dt} \left( \frac{dh}{dt} \right) = \frac{d^2 h}{dt^2} = - g
$$
which is of course just the usual equation for acceleration due to gravity. So we have proven that the trajectory that minimizes the action is the one we expect--where the object just accelerates downward due to gravity in the usual way.
In this example, we varied with respect to ##h##; more precisely, we varied with respect to ##h## and ##\dot{h}##, since those are the "free variables"--they are what the Lagrangian is a function of. Another way to think of why that's true is that, if we specify an initial height (##h = 0## in our example) and an initial velocity (which you can easily calculate from the above), we have completely specified a free-fall trajectory, and therefore we have completely specified the action. (Specifying the elapsed time, if you work it out, is equivalent to specifying an initial velocity.)
binbagsss said:
I have no intuition on why we are taking variations with respect to the metric?
Because the metric is the "free variable". The Lagrangian here (more precisely, the Lagrangian density) is ##R \sqrt{-g}##, the Einstein-Hilbert Lagrangian, and the counterpart to ##h## and ##\dot{h}## in the above example is the metric, since that's what ##R## and ##\sqrt{-g}## are functions of. (More precisely, they are functions of the metric and its derivatives.) And as above, we can think of this as telling us that, if we specify the metric, we have completely specified the action.