Cars are incredibly expensive. Like, crazy expensive. Depending on the country, the type of car you use and how much you use it, owning a car costs between €500k to €2mio over your life (calculated over 50 years). If you have easy access to good public transport, you can save all of that. And while a public transport ticket might seem expensive, compared to all the hidden costs you have to pay with a car (tax, maintainance, value loss, insurance, …) it’s really cheap. For comparison, if you buy year-tickets for public transport for 50 years it’s between €25k and €100k, depending on where you live. So while you might pay more for housing, you save a ton by not having to own a car.
Housing next to public transport can be built cheaper, because it doesn’t have to have parking included in the building. Surface parking costs space, and land value is expensive. Underground parking is really expensive to build and maintain.
Once housing next to good public transport becomes the norm and not the exception, the price difference isn’t that huge anymore.
It usually is, yes, but: