In exchange we get population mobility; without this tax break homeowners would be very reluctant to ever sell their house and move someplace else. Also, housing capital gain isn't completely tax free; we all pay increasing amounts of property tax as the value appreciates. Although those taxes are baked into rents so maybe that's a wash depending on one's point of view.
Policy is hard and unintended consequences are around every corner. For example, I could see an argument for changing the scheme to a special rebate. So you pay your capital gain tax when you sell your primary residence but then get it all refunded when you buy another one. But then this scheme would wind up dinging senior citizens with a massive tax hit just when they're trying to put together cash for some end-of-life care.