I think the reason is simple: once the junior dev is trained, they will leave. To be clear, I am not saying that they are obliged to stay in the company that trained them or being ungrateful in any sense, I am simply implying this is a common outcome from such training. In software industry, the first job switch in 2 years seems pretty common and reasonable, and the dev by that time would be able to strike a better j…
A friend of mine runs a web dev shop and I have seen him train at least six people from zero-to-pro (very smart, fast learners with a math background) and what you described is exactly what happens. Once they become medium/advanced-level proficient they often quit and move on to other, bigger companies. If there was some formal, or informal understanding that candidates "trained on the job" would stay for a few years…
If they had an option to move up and work on interesting problems than I would have stayed.
I suspect many others are the same. The only people hiring juniors are the ones who can't afford to pay mid level devs and when the juniors become mid level what are they to do but leave.