Why does medium not affect the frequency of sound?

Because the frequency of a sound wave is defined as "the number of waves per second."

If you had a sound source emitting, say, 200 waves per second, and your ear (inside a different medium) received only 150 waves per second, the remaining waves 50 waves per second would have to pile up somewhere — presumably, at the interface between the two media.

After, say, a minute of playing the sound, there would already be 60 × 50 = 3,000 delayed waves piled up at the interface, waiting for their turn to enter the new medium. If you stopped the sound at that point, it would still take 20 more seconds for all those piled-up waves to get into the new medium, at 150 waves per second. Thus, your ear, inside the different medium, would continue to hear the sound for 20 more seconds after it had already stopped.

We don't observe sound piling up at the boundaries of different media like that. (It would be kind of convenient if it did, since we could use such an effect for easy sound recording, without having to bother with microphones and record discs / digital storage. But alas, it just doesn't happen.) Thus, it appears that, in the real world, the frequency of sound doesn't change between media.

Besides, imagine that you switched the media around: now the sound source would be emitting 150 waves per second, inside the "low-frequency" medium, and your ear would receive 200 waves per second inside the "high-frequency" medium. Where would the extra 50 waves per second come from? The future? Or would they just magically appear from nowhere?

All that said, there are physical processes that can change the frequency of sound, or at least introduce some new frequencies. For example, there are materials that can interact with a sound wave and change its shape, distorting it so that an originally pure single-frequency sound wave acquires overtones at higher frequencies.

These are not, however, the same kinds of continuous shifts as you'd observe with wavelength, when moving from one medium to another with a different speed of sound. Rather, the overtones introduced this way are generally multiples (or simple fractions) of the original frequency: you can easily obtain overtones at two or three or four times the original frequency, but not at, say, 1.018 times the original frequency. This is because they're not really changing the rate at which the waves cycle, but rather the shape of each individual wave (which can be viewed as converting some of each original wave into new waves with two/three/etc. times the original frequency).

This has to do with continuity of the wave motion. Imagine you had a change in frequency going from medium A to medium B - say 10 Hz become 20 Hz.

How do you make something move at 20 Hz? You need to apply a driving force at 20 Hz of course. But the incoming wave is going at 10 Hz.

To add energy to the wave we must be pushing when it it moving away from us and pulling when it is moving towards us (or pull up while it is moving up, etc). If you move too slowly to keep up you can't give the faster moving (higher frequency) wave any energy.

The only way to stay "in sync" is to have the same frequency. But wavelength can change - that just depends on the frequency and the speed of propagation.

Frequency, in physics, is the number of crests that pass a fixed point in the medium in unit time.
So it should depend on the source, not on the medium. If I take a source that vibrates faster than yours, then the number of crests that my source can create per second (for example) will be more than yours.
But speed of the wave depends on the properties of the medium, for example temperature, density etc etc.

we also know that

$Wavelength = \frac {speed}{frequency}$

From this equation wavelength depends on the speed of the wave (i.e the medium) and the frequency; so it is different for different mediums. Think of frequency in the equation as a constant since it only depends on the source-- so if now speed changes (i.e. medium changes), then only wavelength changes!