Long, long ago, the compact was that employees worked hard for a company for a long time, and were rewarded with pensions and opportunities for career advancement. If you take away the pensions and take away the opportunities for career advancement, your employees will advance their careers by switching companies—and the reason that this works so well is because all of the other companies would rather pay more to hire a senior engineer rather than take a risk on a junior.
It’s a systemic problem and not something that you can blame on employees. Not without skipping over a long list of other contributing factors, at least.
The math remains simple: if you already have an employee on your payroll, how in the world are you not willing to pay them what they can get by switching at that point? That's literally just starving one's own investment.
The real issue is that the companies who were "training" the juniors were doing so only because they saw the juniors as a bargain given that they were initially willing to work for the lower wage. They just don't stay that way as they grow into the craft.
An employee who does not do the effort to re-peg their labor time to market rates for their skill level is implicitly consenting to a prior agreement (when they were hired).
When I started work (this was in the pre-consumer-internet era), job hopping was already starting to be a thing but there was defintely still a large "old school" view that there should be some loyalty between employer and employee. One of my first jobs was a place where they hired for potential. They hired smart, personable people and taught them how to program. They paid them fairly well, and gave annual raises and bonuses. I was there for about 8 years, my salary more than doubled in that time. Maybe I could have made more elsewhere, I didn't even really look because it was a good environment, nice people, low stress, a good mix of people since not everyone (actually only a few) were Comp. Sci. majors.
I don't know how much that still happens, because why would a company today invest in that only to have the employee leave after two years for a higher salary. "They should just pay them more" well yeah, but they did pay them in the sense of teaching them a valuable skill. And their competitors for employees started to include VC funded startups playing with free money that didn't really care what it cost to get bodies into the shop. Hard to compete with that when you actually have to earn the money that goes into the salary budget.
Would the old school approach work today? Would employees stay?