Rainbows in clouds, also known as cloud rainbows or iridescence, are formed due to a phenomenon called diffraction. Diffraction is the bending and spreading out of light as it passes through small particles or objects.
In the case of cloud rainbows, the tiny water droplets or ice crystals in the clouds act as the diffraction agents. When sunlight passes through these water droplets or ice crystals, the light is scattered and bent at different angles. As a result, the different colors of the visible spectrum, like red, orange, yellow, green, blue, indigo, and violet, are spread out and create the effect of a rainbow.