Why do people leave? They leave for all kinds of reasons. But let's just consider the extreme microcosm minority of people who do actually leave for compensation related reasons and dig deeper into that, because that's what you're focused on.
Let's say you have a developer who decides to leave because they aren't being paid enough, and they would like 5% more in their income, and "if only they'd ask then I'd give it to them". That begs the question: If you could pay them 5% more, and you're not, then why aren't you paying them 5% more? If you could afford to give all your employees a 5% salary increase on a whim just because you feel like it, then isn't it also that case that by not proactively doing that, then it is you who is greedy? You believe your employees are worth 5% more than they are being paid, and you can pay them 5% more without hurting your company financially, so therefore the reason you are not proactively giving them a 5% raise is, precisely what exactly? Is it not because you believe that by not giving them the 5% raise that both you can afford and also that they deserve, you are underpaying them and you believe this to be OK? And you believe it is OK and expected for an employee to work for an employer who is not only underpaying them, but also fully recognizes they're underpaying them, and furthermore to that is OK with underpaying them and is not willing to (proactively) change the status quo that they are underpaying? And you believe that the employee should have respect and loyalty to such an employer?
OK, let's start with the basics: If you can afford to give your team a 5% raise, here's what you do: Stop reading this answer, right now, walk out to your dev meeting room, call an immediate all-hands meeting, right this second (yes, RIGHT NOW), and announce to everyone on the team that, effective immediately, everyone is getting a 5% raise. See how that goes over. Will it make a difference? Probably not. 5% is not that much, it amounts practically to pennies as far as your team is concerned, and probably nobody will care. But what it will do is show your team that you're not cheap, and when the company is profitable, they will see the rewards, and that, at least, has value. It also shows that management is aware that they are underpaying the employees and will do what they can to remedy that, and that's important. Even excepting the fact that not everyone leaves for compensation-related reasons, and that the pay increase for changing jobs is usually substantially more than 5%, these things are important.
As for other reasons developers change jobs, I can point to one which is very personal to me and guides my career decisions. I have no loyalty to my company because I believe my company has no loyalty to me. I have been lied to, cheated, had my time wasted, been belittled and berated, by almost every employer I have had. I've had a raise, with gushing praise from my manager, and then a month later been terminated for financial reasons from a company whose CEO told us every biweekly meeting how successful we were. This has happened to me. Companies have no loyalty. Period. Your company too, sight unseen, has no loyalty. You can say whatever you want, but I guarantee you, push comes to shove, every single member of your team is cuttable at any time for whatever reason you want. Except that works both ways: you see all your employees as expendable, and every single one of your employees, sight unseen, sees you as expendable. Every last one of them, without exception. As much as it is a constant battle for your employees to retain their job (by performing their work to the best of their abilities and not doing anything to warrant reprimand), whether you realize it or not it is also a battle for you to retain your employees, likewise, by running your business and treating your people in such a way as to not warrant reverse-reprimand, which usually takes the form of an employee leaving. This is, by the way, not a slight against you personally; I know nothing about you or your company. This is simply how the world works and how employees look at (or, if they don't, then they should) their employers, because so many companies do this that it's safer to assume your employer is trying to screw you and act accordingly in that way than it is to assume your employer is actually trying to be cordial. And that's why employees leave, because employers are expendable.