You don’t have to pay full. When you’re done, you can sell.
Buy for $500k, put down 100k as downpayment. Suppose it’s an interest only loan and you pay $1500 a month for all house costs. In 5 years you’ve paid 90k. If the house price doubles, you’re walking away with 410k.
Renting you’d be putting at least 2k a month, so total 120k. 190-120=70k.
For 70k in stock market to become 410k , that’s a 5.8X growth. Really hard.
In a booming market, with low interest rates, buying makes sense because of leverage.
Obviously you have to do the numbers for rent/buy scenarios and make a decision yourself. There is no right answer.