Fire rainbows occur only when the sun is very high in the sky (more than 58° above the horizon). What's more, the hexagonal ice crystals that make up cirrus clouds must be shaped like thick plates with their faces parallel to the ground.
When light enters through a vertical side face of such an ice crystal and leaves from the bottom face, it refracts, or bends, in the same way that light passes through a prism. If a cirrus cloud’s crystals are aligned just right, the whole section lights up in a spectrum of colors.
The phenomenon is similar to the iridescent clouds, also called “rainbow clouds” —confusingly, they’re sometimes also called fire rainbows—that form on top of cumulus clouds after thunderstorms. Those form after air is pushed up rapidly, causing it to cool and expand. Water droplets condense that can then act as prisms, forming a rainbow cap over the cumulus cloud. (See photos of sun dogs and other atmospheric delights.)