Why is buying apartments a bad investment idea

Why do people advise that buying an apartment in inner cities to rent out/for investment purposes a bad idea if the maths indicates it will pay for itself?