Originally, sort of. But also to work around limitations in GIF (which is palette-based; but see https://en.wikipedia.org/wiki/GIF#True_color) and because people didn't always have true-colour monitors (or ran the monitor in a different mode due to VRAM restrictions) anyway.
In today's context, more for the aesthetic, presumably.