Premeditated data breaches like this are covered under the boilerplate language in your employment contract -- "sharing data with our partners" and other such nonsense.
Not saying I agree but (I think) the issue is that salary data is technically owned by the employer and not the employee.
The salary number itself yes, but it's only useful when linked to the identity of the employee. And in places with sane privacy laws that's illegal to do without the employee's consent.
It is your presonal information and it is not owned by your employer.
Your employer may have some right to share aggregated data, but not data that identifies you.