I think there are several issues.
You might argue that salary "should" be based on merit and qualifications, but these are highly subjective and often evaluated by people within the university who have other vested interests, so there's a substantial risk that internal politics or other factors may not measure merit in a fair way. Given this, existing faculty may prefer a system that puts more weight on objective measures like seniority, and faculty have a lot of say in the administration of a university.
On the other hand, new hires are not really paid based on their merit and qualifications either: they're paid their market price. The dean may not think that Assistant Professor A's qualifications really "deserve" a salary of $X, but if the job market is strong and that's what other institutions are paying similar candidates, she either pays him $X or she doesn't get to hire anyone this year.
Assistant Professor B has been with the department for 3 years. Her qualifications are comparable to those of A, but she was hired in a year when the job market was weak, so she accepted a low salary offer $Y < $X. Since then has received a standard raise of a few percent per year, so her salary is still below A's. She could probably go back on the job market and find a job paying $X, but here she is well on her way to tenure, she has settled in the city with her family, her spouse has a job in the area, and they are disinclined to make another (possibly long-distance) move. Moreover, changing tenure-track jobs is always challenging (she would have to get letters from within her department, but if too many colleagues find out she is thinking about leaving, it will hurt her standing within the department). So she has limited mobility and no real leverage to negotiate for a higher salary.
If she finds out A is making more than her, despite being similarly qualified, she will not be happy. Unhappy faculty who nonetheless have no interest in leaving is not a recipe for a well-functioning institution. And a dean who's in favor of correcting salary inversions will probably get Professor B's vote.