The business has cash saved up. It has 3 options. Give the cash to the business’ owners, spend the cash on improving the business (such as R&D), or keep the cash sitting around.
And businesses often times do all 3 in varying amounts.
However, for a publicly listed business, giving cash to the business’s shareholders is taxable income. An equivalent way to reward shareholders without requiring shareholders to pay tax now is to buy outstanding shares and hence causing the price to go up because the supply of shares relative to demand goes down.
Also, if a publicly listed business awards equity to employees, such as RSUs which tech companies famously do, then buying back shares simply negates the effect of that since giving the employee equity increased the supply of shares relative to demand.