you are right, that selling a house or apartment will get a lot of profit and more instant than renting it. However, sometimes people who rent their houses do not want to sell their houses. they choose to live in a new place, but still want their old house as an asset and investment. So, what they do is rent out the house they own. it will have at least two advantages, the first is that their house may still be maintained by someone else, the second is that the assets they own will have a high price every year.
Selling a house or apartment or other with cash payment can certainly make us have more instant profit, different from renting it. Another thing that might happen if we rent a house is a traffic jam when it's time to pay, I know not everyone is like this but I experienced it where I sold the house but the person who was interested only wanted to rent it not buy it, I decided to give it with a rental system but a few months later the tenant experienced a payment delay, with several times I have given the opportunity but there was no change for the better until finally I reluctantly asked the tenant to leave the house he was renting.
Renting a house is one way that can be done to seek profit or income in the long term, and as you said with two things that are likely to be profitable with a well-maintained house and long-term income, this is a fairly reasonable solution and in my environment there are many rich people who do this.