The players literally signed a CBA for this, for the greater good of all 500 players in the league and not just for themselves.
Are you implying that NBA players prefer to have their salaries capped? Because this is not true at all. Just because something is part of a collective bargaining agreement doesn’t meant that’s exactly how the players prefer everything. They are agreements where both sides make some concessions. If the players had it their way, their would be no cap.