Because that’s how the stock market works, the price of a stock is the current value of assets (including cash) + expected earnings (with some correction factors for risk and time). If the company pays out $x of cash it’s $x worth less. You might not always see it it the stock price because expected future dividend payments are also already priced in.
How do you think it works?
There are plenty of companies that never pay dividends, yet people buy them.
II struggled with this as well for a while. You can look at it this way, they are worth money because they could pay dividends, but they don’t actually have to. Your bar of gold is worth a certain amount of money equal to the money you could sell it for, and your money is worth something because you could buy something with it.