They bought shares in the belief they would rise in price later. Enough people believed this, and bought shares. The increased demand raised the price as they expected, so they made a profit, but then they had to get out again to realise the profit. They had to flick-pass the share to some other dupe. This may be true for you, but it can't be true for everyone.
Future profits are what matters in determining fundamental share prices.
To work out that price, you need the present discounted value formula out of the Corporate Finance 101 textbook. For example, if profits grew by 2 percent a year, and the discount rate was 5 percent a year, then the appropriate price for shares in that company would be just over 33 times current earnings. In the long run, total profits growth should be the same as growth in the economy. Otherwise, the corporate sector would either get bigger than the whole economy, which is impossible, or shrink to nothingness, which is nuts. A rough figure for US trend economic growth, excluding inflation, is about 2.5 percent, so let's say 4.5 percent including inflation for long-run average growth in profits.