To simplify - a company should hire more/pay more until the marginal value of that employee < the marginal employee cost.
If the 2nd best option for CEO would result in increased revenue by 1%, and the best option by 3%, then it makes sense to pay up to 2% of revenue to get that better CEO.
Compare that with the best SWE option (in terms of marginal cost vs marginal gain) vs the 2nd best candidate.
Compared to the CEO, the SWE may be far more intelligent, more hardworking, and directly improve the product more. But pay is unfortunately not based on that or any notion of “fairness”