Because frequency is a matter of timing, not spacing. Frequency is measured in the number of waves that pass per second.
If a signal of light experiences 10 cycles before shutting off, you’re not going to get that signal to be 9 or 11 total cycles, no matter what medium you put it through. These waves might change in their wavelength a bit, but the same number of waves will still happen over the same amount of time.
(Now, if you are moving fast enough so that relativistic effects happen, or the light is coming out of a very strong gravity well, then different observers will begin to disagree on timing, and the frequency might change then. )