When can enemies not see a soldier on a roof?

It is simply based on line of sight, which depends on a variety of factors. These include distance from the roof; objects between unit on ground and the roof; height of the roof...