The simple answer is:
When light passes through a prism, it is dispersed into its composite different colours. For rainbow, when sunlight passes through the water droplets in the air, the colour get separated out.
Let's get into a bit more details for the preparation of the next few posts. When light, in fact any wave, meets a boundary, there is a change of direction depending on the speed of wave before and after the boundary. This is known as Snell's law which states that the ratio of the sines of the angles of incidence and refraction is equivalent to the ratio of velocities in the two media, or equivalent to the opposite ratio of the indices of refraction.
However, the refractive index for different colour of light is slightly different. The refractive index of blue is larger than that of yellow and that of red. Hence white light is refracted to slightly different path into a spectrum of colour. [list of refractive indices]
Rainbow photo: http://www.flickr.com/photos/orvaratli/3605600578/
Prism dispersion: http://upload.wikimedia.org/wikipedia/commons/0/06/Prism_rainbow_schema.png
Snell's law" http://en.wikipedia.org/wiki/File:Snells_law2.svg