The share price kept rising while they were investing profits in expanding.
It's far from a fool proof way of doing things, many companies that prioritise growth over profitability wind up with neither, but Amazon managed it.
As for prices, no computer can work out my preference or not for a Mac over a PC, or a iPhone over an Android, or how much quality I will pay for in a bike. Prices reveal this.
Ludwig von Mises said this was why Communism wouldn't work in 1920. He was right.