Why does the acceleration $g$ due to gravity not affect the period of a vertically mounted spring?
The effect of gravity is only to shift the equilibrium point, so at equilibrium (at rest), a vertical spring will be extended as compared with the same spring in a horizontal position. But this does not affect the period.
The equation for the dynamics of the spring is $m\frac{d^2x}{dt^2}=-kx+mg$. You can change the variable $x$ to $x'=x+mg/k$ and get $m\frac{d^2x'}{dt^2}=-kx'$. So the dynamics is equivalent to that of spring with the same constant but with the equilibrium point shifted by a distance $mg/k$
Update:
when you replace $x$ in you equation you have $x=x'-mg/k$ so you get $m\frac{d^2(x'-mg/k)}{dt^2}=-k(x'-mg/k)+mg$
On the left side you have $m\frac{d^2(x'-mg/k)}{dt^2}=m\frac{d^2x'}{dt^2}$ because the derivative of a constant ($mg/k$) is zero, and on the right side you get $-kx'$ after distributing.
Just look at the equation of motion.
Suppose you hang a spring from the ceiling, and that it hangs a distance $y_0$ from the ceiling in equilibrium (we orient our axis so that positive $y$ points downward). Then, the equation of motion is $$ m\ddot{y}=-k(y-y_0)+mg, $$ and so $$ \tfrac{\mathrm{d}^2}{\mathrm{d}t^2}(y-y_0)+\tfrac{k}{m}(y-y_0)=g. $$ The square of the frequency is given by the coefficient of $y-y_0$, in this case $\frac{k}{m}$, which you'll note does not involve $g$.
The period of oscillation depends on the restoring force and the inertia (mass) which is oscillating.
Gravity is a constant force. When the mass is in its equilibrium position this force is balanced by the spring force. When the mass moves away from equilibrium the force of gravity does not change, only the spring force changes. The restoring force is caused only by the spring force.
Although gravity affects what the equilibrium extension will be, it is not the restoring force, so it does not affect the period of oscillation of a mass on a spring.
However, gravity does affect the period of a pendulum. The gravitational force on the pendulum mass is constant and independent of displacement, but the moment of this force - which causes the pendulum string to rotate back towards the equilibrium position - is not constant. It increases with the angular displacement. The restoring moment (torque) depends on gravity, so gravity affects the period of a pendulum.