An actual, legally enforced law in Crest of the Stars. The Abh were created by genetic engineering and were all given blue hair as part of the process and they kept that when they became independent. The anime shows it as a fairly uniform colour with only a handful of exceptions, but the novels describe it as running gamut from very pale blues and blue-greens to dark blues and purples.
Lampshaded in Zenna Henderson's science fiction short story Crowning Glory, in which everyone except the heroine, Anna Mary, has extremely short hair dyed bright colors such as pink or blue. It turns out that untreated hair, such as Anna Mary has, is something aliens require, and, in return, they're willing to give the Earth medicine that eliminates many degenerative diseases.
Her long blue hair is the defining physical trait of protagonist Karou in Laini Taylor's Daughter of Smoke and Bone. It was originally near black, but she wished it blue and it's grown that color out of her head ever since.
Marlene from Divergent has purple hair, it's a pretty common Dauntless thing.
In Doctor Who and the Doomsday Weapon, Malcolm Hulke's novelisation of the Doctor Who serial "Colony in Space", it's mentioned in passing that a young woman had dyed her hair "dull blue, as was the fashion that month".
In The Dresden Files, Maeve, Lady of the Winter Court, has hair that is styled into dreadlocks, and each lock is dyed a different shade of cold green, purple, or blue.
In the fantasy novel Drink Down the Moon by Charles De Lint, one of the faerie women living among humans who is posing as a young punk musician has natural pink hair. Anyone who sees her (anyone who sees her and due to her glamour is led to think she is human, that is) assumes it's dyed.
In Fire, the spin-off of Graceling, both Fire and her father Cansrel exemplify this trope. Fire's hair is bright red with streaks of pink, yellow, and orange. Cansrel's is blue.
In God Bless The Rockstars, the main character, Zack, eventually comes to believe his wife Georgia's hair is actually pink, as he's never seen it any other colour. It turns out that her hair is naturally a reddy brown colour, like her true father's.
In the Harry Potter series, Nymphadora Tonks uses her Metamorphmagus abilities so that her hair is normally pink, except for the period in book 6 when she was too depressed for her ability to work.
Her son, Teddy, also uses Metamorphmagus abilities to change his hair color. As a baby, his hair is said to be turquoise.
In The Hobbit, Dwalin is introduced to Bilbo as having a blue beard.
Honor Harrington: In A Rising Thunder Madeleine Richter has dark blue hair - not dyed or artificially colored, but the legacy of a genetic slave grandparent whod been designed that way by special order.
Used to great effect highlighting how alien America is to the young heroine of In the Year of the Boar and Jackie Robinson, who sees the principal of her new school has blue hair(Justified as this takes place in the later 1940s, when this wasn't unknown), and merely thinks, "Hair came in all colors in America."
In the Inferno Series, the half-elf Gwynn has green hair. The other elves in the village are described as having various shades of blue hair.
Journey to Chaos: Due to the elevated mana levels in Tariatla compared to Threa, humans can be born with any kind of hair color. It has to do with Lady Chaos' influence increasing the genetic variation in hair pigments. Indeed, Ginger Hasina is shocked that people from Threa can't have blue hair.
In Jacqueline Carey's Kushiel's Dart, Alcuin's hair is white even as a young child. This is implied to make him unearthly beautiful.
In Mushoku Tensei, this is a staple for the demon/magical races, such as the Supards, like Ruijerd, that have green hair, and the Migurds, like Roxy and Lara, that have actual blue hair.
Badi and Atofe have purple and blue hair, respectively, and Kishirika has pink hair.
Sylphy has green hair as well, but that's because of the Laplace reincarnation factor, which she shares with Rudeus, but in his case he gained extreme magic potential and the inability to use touki.
Sieg also has has green hair, but that's probably hereditary
Also of note is the Dragon Tribe, like Orsted and Perugius, whose individuals have silver hair and golden eyes.
Like with the games everyone in Quantum Devil Saga: Avatar Tuner have all kinds of hair colors ranging from silver to pink, green and red. This ends up leading to some confusion regarding Sera where her black hair is completely unheard of.
The main characters in Caitlin R. Kiernan's novel Silk have unusual hair. Robin has green hair. Spyder has white dreads, and the other main character has cherry-red hair.
Members of House Targaryen in A Song of Ice and Fire have platinum-colored hair. Aegon Targaryen invokes this trope and dyes his hair blue to avoid being recognized.
Tyroshi people tend to dye their hair to various unusual colors, often in complex interactions (say, a moustache contrasting with the sideburns and beard, but coordinating with their headhair, or braids of many shades), but they do tend towards shades of blue and green more than most others. Tyrosh is famous for textiles and dyes, incidentally.
Ghiscari have (apparently natural) red and black hair, like tortoise-shell cats.
In the Star Darlings franchise, each Star Darling has a different, usually impossible hair color.
Lost Stars: Secondary character Kendy Idele, who is human, has dark green hair. The color is natural, a quirk of the human population native to her homeworld of Iloh.
In the picture books Stella and Sam by Mary-Louise Gay and the associated Animated Adaptation, Stella's hair is flame red, while Sam's is bright yellow.
The Irali from The Stormlight Archive have golden hair. Not blond, but actual metallic gold. Hair color also gets passed on proportionally, meaning that Adolin, for example, has half blonde, half black hair, resulting in a wide range of possible hair colors.
The novel Super Folks, one of the earliest deconstructions of the super hero genre, has a Super ManExpy named Indigo as its main character. Since comic books always shaded Superman's black hair with blue highlights, Indigo actually does have blue hair. Thankfully, none of his Secret Identity's friends ever seem to notice.
Pretty much everyone in Tough Magic has unusualy colored hair, eyes, and skin; which makes sense, considering that their all fae.
The Twelve Kingdoms novels. The starting setting is a plausible, normal Japan, where people have the Japanese hair colors and such. Then, the main character, Youko Nakajima, has almost red hair and it's completely natural (although people accuse her of dyeing it red to bring attention to herself). Then, a platinum blond (almost white-haired) Japanese looking guy appears from nowhere and wants to take Youko to his world (making people assume he's a gangster and she's secretly his girlfriend). When she finally goes to this world, between all the suffering, she sees Japanese-looking people of all skintones and hair colors. All the colors in a rainbow. The anime shows it with beautiful detail, but not as impressively as it is the novel description. But taking in consideration that they are sorta likealiens...
Stephen in the Wayside School books is described as having green hair. The third book reveals that this is due to excessive chlorine in the local pool.
Polly in Quicksand House has green hair, and Darcy has blue hair. It comes from their Terramyte genes. It probably pales in comparison to the fact that they both have antlers, though.