The root reason is really simple. The company will have to spend 5k more to keep you, while it doesn't have to if salaries are secret.
That covers the case when talking about salary is prohibited by a company policy.
Why people don't tell their salaries? Well, I do tell to (some of) my co-workers. None ever said to me: Wow, you make a lot of money! - Instead, they say: Wow, I could be making more. - So they'll start looking for other jobs (not counting lots of other factors beside paycheck. Lots)
Anyway, top reasons why people don't tell how much they earn:
1) We deny a chance of making others sad;
2) We fear our bosses will discover that we talked about our salaries, thus a) being the reason why an employee quit; b) being the reason why an employee asked for a raise (increasing the company expenses);
3) Fear of security; Once your salary is "out there", the watercooler talk might be: Wow, do you know how much inerte makes? And you don't know who'll end with this information.
4) Compensation isn't a factor when there's blame to assign: Wow, inerte makes lots of money, how come he did this stupid thing? - As if someone less expensive, with a similar set of responsibilities, is allowed to make more errors.
And you know what? Some of these reasons are true. I know how much 6/7 members of my team earn per month, and I know I am being underpaid. In 3-5 months I am probably asking for a raise. If they deny, I will at least dip my feet into the job market, and see if I can also get 33% or 90% more.
Yes, someone earns 90% more than me for something that I know how to do it. He has more experience on some other stuff, but he's also friends with the boss. His salary is so above the market that I suspect someone is getting something out of this (aka, corruption?).
I tell how much I earn because I do want others to look, if they want to, for better paying salaries or to negotiate their current ones.