Becoming a landlord isn’t really that different from becoming an investor, for example, as to become one you need a certain ammount of capital and under capitalism no matter where you put that capital you will be exploiting others. And as we live in a system full of crises unless you have “a few million” very diversified anyone could be losing everything in the next crises or when a new goverment comes around, specially if through a coup, and changes the rules. So it’s kinda hard to ask people to give their safety net away when the vast majority are at most a few problems away of losing it all.
So I would say your question makes more sense if we are talking about how much capital a person has, rather than what they do with it (unless they are doing some even worse things with it). So someone with a second house can be a communist no problem, but someone with ten should at the very least be using some of that money to further the cause, not only by giving it to a communist party and the like but also by giving free housing to some who need it, if they consider themselves communists. If they could sell a few houses and use the money to further the cause that’s fine too, although in some countries even that many houses might not be enough to pay for something like a cancer treatment, so it’s hard to say exactly.
The same would be valid if the person had shares or companies or whatever, although if the person directly owns companies the person should definitely give everyone a good salary and let the worker unionize and try to spread it to more people too.
You can always rent it for a while and think better about your situation. Just selling it and putting the money in the bank just means the bank will be using your money to possibly cause way more damage than you could anyway. Buying shares, at least if you don’t even work in the company is bad too, so holding on to the apartment is not the worst thing you could do and if you sold it it’s possible the new owner would just rent it too.
If you rent you could always see if the person living there would like to buy it from you and so you can even give them a discount based on how long they lived there if you think it’s better too.
If you already know when you need the money you can alway do the math and see what is the best option for you. Let the money stay in the bank, keep the apartment until them… And also check the risks, as in my country, as an example, the goverment has taken peoples savings about thirty years ago when the inflation was bad so who knows if they will do it again. So if you were in my country puting the money in savings would have an extra risk, while perhaps there might be countries where the goverment has made housing cheaper before and could do so again, meaning holding on to the house might not be the best idea either.