Depending on what you mean by "equivalent", yes it could make some claims of discrimination based on race/sex/etc slightly harder to defend against. It does not "open" a company to lawsuits as opposed to being closed to suits by paying equivalent wages. It is one of many many things that could be a factor in such cases. And a lot of companies decide it is worthwhile to do despite that.
> You can and should ask your peers what they make. This is totally legal and encouraged.
It's not encouraged by many companies, and some try to discourage it including by trying to get employees to agree not to, whether or not it's legal.
What is much harder to accept, and builds resentment and apathy, is something that feels arbitrary or unjust.
Perhaps the more productive worker is more productive because their work is not high-visibility. Maybe it's the arbitrary luck of having been assigned a more successful project.
https://www.costanzo-law.com/google-hit-with-lawsuit-over-cl...
It's illegal to pay differently on the basis of sex, race, or other protected classes. It's perfectly legal to pay differently on the basis of performance or anything that isn't a protected class.
The vast, vast majority of workplaces in America pay people at the same level different amounts.
The real problem for companies is when the explanation comes down to "Sandy negotiated harder than you", "Sandy got a higher offer from a competitor so we had to match it to keep her", "we're paying you significantly under the market rate and are hoping you don't notice or aren't too bothered by it", etc.