The underground caverns were divided into underground spherical cavity and underground tunnel. From bean-slab theory and energy principle, the catastrophe models of underground spherical cavity and tunnel were built and the necessary and sufficient condition of roof failure was derived. Taken the cavern roof of Wenfu phosphate mine for example, the minimum thickness of roof was derived. The analysis of spherical cavity shows that the roof fails more easily when the roof thickness is smaller, the elastic modulus is smaller, the Poisson's ratio is smaller and the roof span and loads are bigger. The analysis of tunnel roof shows that the stability of tunnel roof is closely related to the vertical load and the horizontal load. In order to guarantee the roof stability, the observation of load acted on roof should be reinforced and some control measures should be taken according to the necessary and sufficient condition of roof failure.