That happens because of refraction.
At the boundary between two different media, each color bends a tiny tiny tiny tiny amount different from how the other colors bend, so they come out of the other side all spread out.
5.2m questions
6.7m answers