There are two main reasons. One is linked to the position in the hierarchy and the second one to the very common personality of programmers. You can't change the former, however, you have more control than you think on the latter.
Most developers are positioned at the very bottom of the pyramid. This is fine: usually, nobody expects anything from you other than writing lines of code. But many developers are providing much more value than the person just ahead of them, while generally having no possibility to earn more and be paid what they worth. The reason is that in our societies, we still think the salary is bound to the position in the hierarchy. The analysts or project managers are higher in the hierarchy, so they should be paid more according to the rule. The problem is easy to spot: position in the hierarchy in many cases is not directly related to the value you provide.
But why do many developers accept to be paid less than they worth? Developers and engineers in general tend to be introverted people. Introverts are often abused by extroverts. Some are aware of their value, but feel they have no control over their destiny, while others have been told since childhood that they worth less than others. The former are convinced there is nothing they can do and the latter don't know there is something to do at all. This leads to stagnation. Many extroverts are intuitively aware of that and use it heavily in their interactions with introverts. You need to take advantage of your introvert personality to survive in this world of extrovert people.
As a developer you are responsible for your current situation. If you are really paid less than you worth on the market, you need act on it.
Finally, I want to illustrate how this perverted system can sometimes work against itself. Salary grades, for instance, can be very effective in many ways, but when poorly used and/or in strongly homogeneous companies (companies with lot of different skills involved), they can lead to very difficult situations for the employer. Below is the true story of one of my best friends.
My friend started as a programmer in a big hospital. Thanks to his hard work and dedication, he quickly became Oracle DBA, which was a critical position in a company where data is both sensitive and valuable.
The hospital worked with grades. Grades are bound to your position in the hierarchy, length of employment and diplomas. Salary increases were automatic and fixed in advance. In fact, he knew how much he would earn at every step of his career.
My friend got an offer to become DBA in another company that didn't use salary grades. By accepting the offer, his salary could be increased a lot. Because he liked and respected the hospital he worked for, he decided to talk to the boss, asking for an increase. He just asked for what he was worth on the market.
The boss refused. It was impossible because of the grades and the unions would not let that happen.
My friend left.
The hospital eventually hired an external consultant (not bound to grades) and launched the recruitment process. The consultant did not know anything about the infrastructure in place, so his learning curve was huge. The hospital lost lots of money training him.
The hospital carried on losing. They could not fine a qualified employee to replace my friend and are still using the external consultant at 5 times what my friend asked for.
That was almost three years ago. My friend is still at his new place and climbing the hierarchy ladder very fast doing what he loves.
The hospital is still paying 5 times more.