In my Fantasy story I have decided to integrate gnomes which are about 2ft tall and have human intelligence, but most notably come in a variety of skin colors and hair colors. You have gnomes with light blue hair/skin, subtle red skin/hair, purple hair/skin and other colors which don't don't exactly neon or superficial looking. My influence of this was seeing how colorful tropical birds and poison dart frogs are, and seeing how this natural vibrant colors would work on a fairly human creature. I thought of multiple ways to explain the variety of vibrant colors, such as the gnomes are poisonous or they come from a very colorful biome (maybe a coral reef type place on land?) but this wouldn't explain why they come in a variety of colors instead of one. I was also thinking the gnomes could dye their skin to show which tribes they come from, but I wanted to see other people expand on these ideas or come up with more interesting ones. Also note that magic does exist but in a much weaker and sometimes undependable form.
Look at humans; hair color and eye color vary among the population, while having little to no direct effect on fitness. Different eye colors aren't much selected against, so evolution doesn't stop them from happening.
So you don't need a grand reason for the gnome colors. Like hair color and eye color, just random variation in the population can explain it.
If you want a more specific reason, perhaps the gnomes long tended to choose unusually-colored gnomes as mates. Over time this could result in sexual selection like the peacock's tail, only instead of a large tail, the selected trait is having random and bright coloration that's different from other gnomes.
Color evolves for a few reasons.
Camoflauge is one obvious one. A being that lives in a background of a particular sort of color will have a huge advantage if they blend in. Perhaps gnomes live in a very colorful area.
Another reason is attraction of mates. Peacock feathers and baboon rumps are two examples. Perhaps they are more colorful at some point in their reproductive process because "blue-and-silver-armed guys get all the girls."
Another reason is identification especially at a distance. Baby gnomes can spot momma gnome by her distinguishing color pattern, and know to go to her and not the other gnomes who will not feed them. The boss gnome has just this particular pattern so you can spot him coming.
Another reason is as a marker of age. Maybe very young gnomes have one color, young adults another, middle aged another, and old another. Think silver-back gorilla or the fledgling colors of many birds. Knowing that this lady gnome is a good healthy pink color may mean she is just the right age to ask out for a cup of whatever gnomes like to drink. But if she starts to get those orange streaks, then she is the one to ask for sage family advice from an elder.
Another reason is that some animals allow themselves to be (or cannot avoid being) colonized by microscopic life. Fungus in the fur, bacteria growing under the nails, etc. As Sid the Sloth said, when he migrates south and the fungus in his fur dries out, he starts to look pretty sharp. Maybe gnomes allow such colonization because it makes them taste really terrible to predators. Or maybe they can't avoid it in the place they live.
Some animals get color from the things they eat. Flamingos that don't eat their usual food can be white. Maybe the food gnomes eat is multi-colored. Or different colors in different regions. Or during different times of the year.