What you say only works if everyone is doing it. But if you're spending resources on juniors and raises, you can easily be outcompeted and outpoached by companies using that saved money to poach your best employees.
give a big enough raise and they won't want to be poached. You won't retain everyone, but your goal probably isn't to compete with Google to begin with. So why worry of the scenario of boosting a good junior from 100k to 150k but losing them to a 250k job?
In some ways you will also need to read the room. I don't like the mentality of "I won't hire this person, they are only here for money", but to some extent you need to gauge how much of them is mission-focused and how much would leave the minute they get a 10k counter-offer. adjust your investments accordingly and focus on making something that makes money off that.
You're falling for the exact same fallacy experienced by failed salesmen. "Why would I bother investing time in this customer when they're just going to take my offer to another dealership for a better deal?"
Answer: you offer a good deal and work with people honestly, because if you don't, you'll never get a customer.