Or why doesnt the government buy a block of flats and allocate one to each MP while they are in office?
Once again it's hang over from the past. Until Lloyd George arranged for MPs to be paid a salary only those who had the necessary means, or were supported by a trade union or similar group, could afford to be MPs.
Before the EU took over governance of this country MP's hours were somewhat longer, and their holidays somewhat shorter, and there was no way MPs from outside of London could get home. Tory MPs often booked into their club for the night and the others had to make do by purchase, rent or whatever arrangements they could make with their union.
The present situation started with Harold Wilson. The Government had just devalued the pound and were on their way to going broke and the MPs wanted a pay rise.
HW didn't dare due to public perception so introduced expenses/allowances.
Here endeth the first lesson!
Roy.