Buying an apartment with cash, implications

Yes, it's possible. But the (already low) yield would be heavily affected by the costs of the agency, here anything involving a human coming to your property in person costs a lot of money.

Go with whatever makes you feel comfortable. But also consider educating a bit yourself on the topic. Investing in the stock market is not (necessity) gambling and allows you to easily and greatly diversify your portfolio, while if you put all your eggs in the same basket you'll have a single point of failure.

Since you brought up inflation (not really a problem these days), in that sense it'd be better to have a mortgage since your debt will be worth less in the future than it is today.