A rainbow is a meteorological phenomenon caused by reflection, refraction, and dispersion of light, usually sunlight, in water droplets.
Rainbows are typically seen when there is sunlight and water droplets in the air, which is why they are seen after rainfall. The sunlight gets refracted as it enters the water droplet, reflects off the inside surface, and then refracts again as it exits, creating a spectrum of colors.
Thus, a rainbow is seen only after rainfall because water droplets in the air disperse sunlight into its constituent colors.