Well of course you pay more by renting, otherwise there would be no landlords. The difference is however in most cases not too big, and the effect of being able to put more money into the stock market, instead of locking it down in a 20% input for an apartment purchase, is much greater.
Example with some common prices in the Swedish housing market.
2-room apartment in central part of my city costs about 300k-350k USD, current laws force you to at least put in 15% yourself to even be able to apply for loans at the banks. 15% of 300k is 45k USD, which would then leave you with a loan of 255k USD if the banks accept it. With current interest rates of around 1,5% you'd roughly pay 300 USD monthly for that loan. Then you have fee to the housing cooperative which can differ a lot, but a pretty average fee for 2 room apartment is around 400 USD monthly.
All in all you pay 700 USD for that apartment every month, not counting paying down the loans as as expense since it's actually a form of saving, and anyhow that money would have bigger effect on the stock market.
Renting an apartment like that in similar area would cost you about 900 USD monthly. So you pay 200 USD extra every month = 2,4k USD extra every year, for renting. Say you live 10 years in this apartment, would mean you'd in this period pay 24k USD extra for renting instead if you'd bought.
BUT, you still have 45k cash available since you didn't buy your home. AAGR of passive index instruments is around 7%. In a period of 10 years this money would almost double on the stock market:
45000 * (1+0,07)^10 = 88,5k USD
Meaning you'd gained (88,5-45)= 43,5k USD in 10 years from the stock market, thanks much to compound interest. Now then you payed 24k USD extra for these 10 years for renting the apartment, which would leave you with a total profit of (43,5-24) 19,5k USD.
If you just look at it from an economic perspective, you're better off renting your apartment as shown. However there are of course many other things to consider, the positive psychological effects of "owning" your own home; being able to do what you want and not reliable on someone else. Also at least in Sweden it's very hard to get a rental apartment contract, in bigger cities there are queues of 10 years if you want a good apartment, in Stockholm even longer. So sometimes you have no other choice than to buy your apartment, me myself.
Maximizing profits = rental apartment in combination with investing your money into stock market.
If you don't care about maximizing and want more balance, buying is better.