It happens like that because that's what refraction is, by definition. As Rob Jeffries's answerRob Jeffries's answer shows, there are solutions of Maxwell's equations where a no frequency shift refraction happens across the interface, so it is possible. When we observe such behavior, i.e. an elastic interaction with the boundary, we call it "refraction".
But we are making a tacit assumption that the interaction with the interface is elastic, i.e. conserves photon energy, and no energy is lost as heat to the mediums as the process happens. We are also making a tacit assumption that the interaction with the interface is linear, and thus there are no multiphoton processes which would double, triple, ... the light frequency. These latter would be theoretically possible, but one can also make a handwaving argument that these latter kinds of interactions are highly unlikely given the interaction region's thin nature and if the light intensity is not too high.