OK - so don't hire employees, but contract with contractors. Seems a pretty simple problem, yet few companies I talk to want to go down that route.
"We're looking for someone who's in it for the long haul" or "we value loyalty" are some reasons I've heard from companies that won't consider contractors.
In some situations, that's probably fine. In many other cases - fast tech-driven startup-type stuff - contracting probably makes more sense for precisely this reason. The company's needs can change quickly, and having a lot of staff that don't know X but only Y is a competitive problem.
"But smart people can learn X too!" Well, yes, to a point, but probably not as well as the people at your competition may already know it. And who says all those smart people really want to learn X? If you're really switching from Y to X, some Y devs may resent that, because Y can handle the workload too. They may not put all the effort in to learning X, because they see it as a fad, or a dangerous pivot that is doomed to failure, etc.
"Smart people can learn new tech X too!" is condescendingly treating devs as interchangeable parts while damning with some praise ("but they're smart!")
"If your developers are either incapable of pivoting to a new language or flat out refuse to, then they are terrible developers."
You've just done 3 years of Rails development, fighting all those version bugs, pulling all the late nighters, getting every rock solid and scaling out to the moon. Yay! Launched, everything's great, and you're rocking it. Then your board of directors signs a deal with MS for Bing tie-in, and MS invests some money in your company, but you have to pivot to ASP.NET/C#. In 3 months.
Do you refuse? YOU TERRIBLE DEVELOPER!
What's that? You'd rather keep doing Rails, so much so that you'll quit your job and move somewhere else to get a chance to keep working on Rails projects? That describes most of the Rails devs I know, and I wouldn't say they're "terribly developers" at all. Well, a couple aren't great... :)