The appearance of colors is because of difference in refractive indices for different colors even though the medium through which light travels is same. When white light hits the glass at an angle, different colors of light are refracted at different angles.
In case of glass plate, these colors again hit the other surface of glass which is parallel to the first surface and hence these colors refract back into the initial angles i.e final and initial direction of travel of all colors is same and if the glass plate is thin enough all the colors almost hit the second surface at the same point and hence the output color is apparently white.
But in case of prism, these colors hit the second surface which is at a different angle than that of first surface and in this case the deviation in direction of different colors is added constructively. Thus all the colors travel in different directions hence making a visible deviation in the path of different colors.
You can think of a rectangular glass block as equivalent to two prisms joined along the diagonal. So, while first prism splits white light into Spectrum the second prism will undo it so light emerging from glass slab will be white again. If the slab is not rectangular then the spectrum will not be cancelled.
We may refer to dispersion of light as a special case of refraction too. now we now that refraction is bending of light at the interface of two different media. One important feature of the glass slab is that the light gets refracted twice and the two faces of glass slab are parallel to each other . see the figure below:
In case of dispersion, the white light gets split into its constituent colours. Since according to Cauchy’s formula, refractive index of a material depends on wavelength of light,therefore, refractive index of the material is different for different colours/wavelengths.
Now see the figure below:
As the refractive index of the prism is different for different colours, therefore , different colours deviate through different angles on passing through the prism as shown in the figure above. In this case we should note that the opposite faces of the prism are inclined to each other and not parallel.