A simple solution congruent with these principles could be:
Selling the house should be restricted to yield the amount of money you put in. This excludes money spend on repairs, etc., and is to be adjusted for inflation.
You can keep living in the house as long as you are alive. Once you are dead, you lose the house and the inheritance will be the same money you would get from selling the house/apartment under the regulated terms.
The next renter of the regulated public housing apartment would just pay rent again until they have enough in their portfolio and then stop to have to pay rent.