Your question extends well beyond electromagnetic phenomena to waves in general. For example, when sound (a pressure wave, which is arguably a lot simpler than an EM wave) moves from air to water, it too undergoes a change in wavelength while retaining the same frequency.
So why in general are wavelengths mutable but frequencies invariant when waves of any type travel between media that change their propagation speed?
It's actually pretty straightforward: It's the only way to keep one wave from "getting ahead" of itself and ending up in the future.
Think of wave cycles as clocks that just happen to be moving, as in those sinusoidal diagrams where you get a sinusoidal wave by projecting a point rotating around a circle onto a moving line. An observer at a distance will see this clock keeping a certain time, say 60 cycles per second, at it travels.
If some segment of that clock then inexplicably started moving at 120 cycles per second, it would literally pull ahead of the other segments in time, counting out new seconds twice as fast as before.
So, while it's unusual to express such issues in terms of causality, there certainly is an aspect of the need for time measurements to stay constant, and that aspect of the situation for any wave does require simple changes in medium not to result in changes of frequency.
With all that said, here are two important qualifiers:
(1) You can always create a new clock frequency based on the old one. If you happen to own a green laser pointer, it internally contains a frequency doubler that takes every half wavelength of an infrared laser and converts it to a full wavelength of green light. This does no violate causality for the same reason that adding a second hand to an old-fashioned analog clock does not violate causality: You are simply adding a finer level of measurement to time by breaking up the earlier cycles into smaller ones that still fit within (and do not get ahead of) the larger, earlier cycles.
(2) The trickier point, and one that leads to some interesting issues, is that wave frequencies do change when frames are in motion relative to each other. Such changes are called Doppler shifts: Waves originating in a source that is moving towards the observer, such as the sounds of an approaching ambulance, are perceived as having a higher frequencies than expected, while than waves originated by a source moving away from the observer, such as the ambulance after it has passed by, are perceived as having lower frequencies than expected. That's why I said "an observer at a distance" earlier, so as to avoid immediate consideration of these relative motion effects.
This brings up an interesting point relative to your question: Why don't Doppler shifts undermine causality? Wouldn't the approaching ambulance in effect have a faster "sound clock" than the the one that is moving away from the observer, and so be moving more quickly into the future than an ambulance that has already passed?
The simple and not-very-satisfying answer is that the causality rule I mentioned earlier only applies locally, that is, because sound in the air is in direct contact with sound in the water, the sound in one or the other cannot begin vibrating faster without creating a contradiction at the interface between the two.
That's correct, but again, it's not a terribly satisfying answer. The problem is that once you get into your head a vision of the physical ambulance speaker diaphragms vibrating faster enough to give that higher-pitched sound, it become hard not to wonder whether the entire entire ambulance, including the clocks within it, might not also be "vibrating faster" than you are as long as the ambulance is approaching. We of course know from direct experience when driving and riding in vehicles that this is not the case, since we don't wind up at Grandma's house sooner just because of the Doppler effect makes the vibrations of our voices during the trip sound higher pitched from Grandma's perspective -- assuming Grandma has very, very good hearing! However, some sort of conceptual reconciliation does seem to be needed.
So, let's look at that vibrating speaker diaphragm issue in particular: Does the diagram vibrate faster? Grandma, being a former astrophysicist and have in here possession a particularly find long-range telescope capable of detecting even minute vibrations, watches you travel from her high mountaintop abode. (By all accounts, you have an interesting Grandma.) She observes voice and other vibrations in your vehicle and detects no discernible difference from the rates she expects. Yet when she looks at the reading from her equally sophisticated super-sized very-long-distance parabolic microphone (don't say anything bad about Granny while traveling), she hears a higher frequency that does not match what she sees in the telescope!
So what in the world is going on here? How can both observations be correct?
The trick is that I haven't told you about all of Grandma's data yet. Very shortly after you begin your trip (there is a very small but detectable speed-of-light delay), Grandma sees you begin to move in her direction. With light, that motion seems to be very close to the time she sees, undetectably close with ordinary instruments in fact.
However, she does not hear you yet! In fact, a good portion of you journey is over before her microphone picks up any sound at all -- and when it does, it is the sound of the start of your journey, much delayed. From that point on the sound plays out as if on fast forward. Remarkably, this accelerated rate works out to be just fast enough to compensate for the lost gap in time, so that by the time you get to Grandma's house, the reality portrayed by light and the reality portrayed by sound are once again in synch, at least as far as human eyes and ears are concerned. Causality is saved, because everything that appeared to be happening faster than normal time was in fact just a sort of delayed recording of events that had already happened.
(You can witness this same effect yourself by having someone at the far end of a football field clap very loudly -- cymbals work better! -- and noticing that you see them clap before you hear them clap. This is exactly the kind of delay Grandma sees with her instruments, only larger and with Doppler effects added.)
What is happening in cases like this, then, is that the "message" conveyed by sound waves is being "bunched up" (technical term) into a shorter sequence that does not arrive until a bit later, leaving a gap of silence.
A useful analysis technique is to analyze the extreme cases of such phenomena, since these often give you a better feel for where the interesting parts are. In this case, imagine driving (or more realistically, flying) towards Grandma's house at just under the speed of sound. What happens then? Well, think about it: It's a horse race, with sound just barely winning and just barely arriving before you do. So, for almost the entire journey, Grandma hears only silence while watching (with some trepidation one would imagine) you fly towards her house at several hundred kilometers per seconds. Only at the very end does she get a burst of sound that represents your entire trip towards her house, hugely Doppler shifted so that for example your voices would be in the extreme ranges of ultrasound.
Now with that I'll end, but leave a bit of a tickler for an issue that is beyond the scope of your question.
I mentioned that Grandma, with her very good optical telescope, actually did see a bit of delay in getting images, since of course light is very fast, but not infinitely fast. Does that mean that there is a still faster "instantaneous" reality lurking behind the speed of light, one in which all events are exactly synchronized and the light is only giving the appearance of some delay? After all, Doppler effects apply to light too. They are for example the cause the red shift seen in the spectral lines of galaxies that are moving away from us at very high speeds.
So, is the time delay caused by the finite speed of light also an illusion?
Here's the surprising answer: no. A fellow named Einstein notices that in the case of light, there is some kind of absolute cosmic limit going on, and from some early experiments he postulated a very weird idea: Light always to travel at the velocity c, or about 300,000 km/s, no matter how you are moving. From this simple postulate and one other (physics doesn't change when you are moving), he constructed the entire fabric of the special theory of relativity, for which he later received a certain amount of notoriety... :)
Now, here's what interesting about that in the context of your question: For the special case of light, motion does have a real impact on clock speeds! That is, you really can construct cases where, with the proper combination of speed and acceleration, you can make one system slower in reality than another. This is not abstraction, since for example if you have ever used a GPS navigation system, the proper location of your vehicles requires that the slowing of time due to relativity effects (speed and some others from gravity) be taken into account.
Very roughly, here's why: Since nothing travels faster than the speed of light c, all of the parts of you and the machinery around you must also interact with each other no faster than the speed of light. That means there can be no greater or "absolute" time standard by which to measure their motions; whatever light does, that becomes the final and only meaningful result. Play that idea out against the postulates I just mentioned, and you find that fast motion sort of "sucks out" or makes unavailable a large chunk of the available light velocity needed for your internal systems to move quickly. If you travel at almost exactly c, almost nothing is left of the internal fraction of c needed for atoms to vibrate and clocks to update. As observed by someone else outside of your domain, your time seems to slow to a crawl.
Yet another mystery lurks there, however, since that "just a crawl" analysis applies in both directions -- that's why they call it relativity!
But again, that's another story, and I think it's time to draw this answer to a close.