Training junior people makes sense economically only if they get up to speed and positive productivity within a small fraction of the time they'll be with your company.
Since a bad developer creates enormous negative productivity, it can be years before a new programmer's contributions are productive at all, let alone greater than the ongoing opportunity cost of the time spent mentoring them, let alone the sunk cost of months to years of mentorship.
This time makes sense only to invest if you expect the developer you trained to stay with you for many years. That expectation has become less and less rational over the past couple decades.
Nowadays if you take on and train a junior, you're taking the loss on that training - not to train someone who's going to be a good mid-level developer in your own company, but who's going to jump ship for somewhere else well before you can make back the senior developer time spent on them.