When CEOs and others acquire stocks as employment compensation - e.g., through vesting RSUs or by exercising stock options - they owe taxes based on the value of those stocks whether they sell those stocks or not. For RSUs, they owe ordinary income taxes on the market value of the stocks when they are acquired. For options, they owe ordinary income taxes on the market value minus the price they pay.
So CEOs and others often sell some of their shares in order to pay the taxes they owe. In Mr. Musk's case, e.g., he exercised more than a billion dollars worth of TSLA options last year - i.e., the market value of the shares was more than a billion dollars more than the price he paid for them. He then sold more than half a billion dollars worth of those shares in order to pay the taxes due on them. Otherwise, he'd have had to come up with that much cash some other way.
In Mr. Cook's case, he typically doesn't sell the shares (for tax purposes) himself. Apple withholds a little more than half of the shares he would otherwise get so that it can remit their value to tax agencies.