If salaries are private, then salary is purely a function of negotiation between employer and employee. Presumably both are happy, or at least happy enough not to terminate the relationship.
If salaries are public, however, then a ton of other variables get thrown into the mix. For example, it's possible to end up in a situation where I'd be happy to stay for a certain salary, and my employer would be happy to give me that salary to keep me, but because they can't offer all my peers the same salary, it doesn't work out, and nobody is happy.
And that doesn't even take into account all the extra interpersonal conflict and rivalry that transparent salaries could cause.
The mitigation for both of these issues is, of course, is to base compensation on objective performance rankings. But that's a nontrivial problem. How do you compare a sales guy to a developer to a DBA? Even if you did come up with a mostly fair solution, it would still invite endless discussion and dissatisfaction from people who feel the system wasn't evaluating them properly.