That is what gives it value to the purchases of the stock.
It is purchased because the buyer expects to earn more from it than they paid, and that they likely can pass it on later.
The value of stocks is certainly connected to real value, and it is one of humanity’s greatest inventions.