There's another phenomenon here. Almost by definition, average developers are not going to get big raises. They'll get average raises. The average developer raise is probably 3-5%, which is not big but it's more than the average raise across all professions, at least in the US.
This leads to an interesting question: why can the average developer get a big raise by switching jobs? I think at least part of the answer is that companies simply have more information about employees who've been around for at least a few years than they do about potential hires still on the market. It's a lot easier for a company to realize an employee is about average once that person has been on the job for 12+ months than it is during the interview phase, where the questions are heavily sandboxed and generally focused on basic problem solving ability rather than the candidate's ability to convert that into business value.
Finally, in general people who are average but think they're above average really do not like to confront the fact that they're average. So average developers with big egos being offered average raises will often very vehemently argue that the problem is all with the companies they've worked at and never with themselves.
---
Another point worth focusing on here is that raises are really determined by the business value that you're producing, not your raw intelligence or passion for coding. Very smart coders may or may not be any good at converting that talent into lots of value for the company. It may even be that sometimes a less talented coder gets offered a much bigger raise because other skills allowed them to create significant value.
I think this explains why so many folks are average but think they're above average. It's because they might indeed be above average in some metrics, but not the metrics that matter to their employer.