So you give it back to the shareholders, and a buyback is tax advantaged for the shareholders compared to a dividend.
* if you are, say, Pepsi, and you have a very good year, you might want to “bank” some or all of those profits for a lean year or for some future investment. But the CFO doesn’t put $10B in a bank account, they invest it. If they put 10B into Apple it won’t have any legal implications (Apple is so huge) and it’s probably a better return than anything else available.
But when you are Apple the sums are so huge and the choice of places you can invest so limited, that giving it back to the shareholders and letting them decide is pretty much your only option. A good problem to have.