Formation of spectrum by a glass prism takes place because:
the light of different colors refract with different angles of refraction
Different colours of light are refracted at different angles. This difference in the angles of refraction of different colours during refraction results in a colourful spectrum.