Because in my experience I was constantly reading their unreadable code, then telling them why it's wrong or bad or not fitting in a digestible manner and then waiting weeks for a refactor.
Iterate that for a month. Mentoring them took way longer than it would have taken me to write it from scratch. Not that dissimilar to trying to using AI for where it sucks (larger, a tad more complex problems).
It only makes sense if you look at it as an investment, because they will eventually improve.
The problem is that corporations are not holistic organizations. In theory¹, a company could not have any juniors and always just hire seniors from the outside. And if your boss has reason to believe that this is more cost-effective, then they have to strive for that, even if they're well aware that it cannot work when all companies strive for that.
¹) In practice, I've actually found that juniors are important, too. If you staff a project team with only seniors, you quickly end up in a situation, where they don't talk enough to each other. They know how to solve things technologically, so they don't need to tell each other about their challenges and what solution they chose.
Similarly, you likely end up in a situation, where only big problems are being tackled, because everyone can tackle big problems and they're just very visible, highly prioritized problems. But when you add up enough small problems, they become just as problematic.
Honestly at this point I do try to take some of the ai fears seriously, these creeps are definitely trying to replace human labour with machines the only comfort I do get is that if they really do manage to create an artificial super intelligence based on the human brain it will definitely destroy them.