Color and imagery play such important roles in all forms of media. They can enhance how we might view a character or act as a device for foreshadowing. Some colors can blatantly symbolize who's good and who is evil, or denote where the character's loyalty resides. While it's easier to see on tv and in film, it's just as important in books.
First, what do the colors mean? Taking a look at Judy Scott-Kemmis' website Empowered by Color, she outlines the different emotions created by color.
Red: Generally this is the color associated with passion, sex, energy, and ambition. But it's also the color of anger (which is generally why people might have heightened emotions when sitting in a red room).
Orange: Social communication and optimism. It can also be a more negative sign of pessimism.
Yellow: Color of the mind and intellect but it can also suggest impatience and cowardice. (Maybe this is why the mind stone in Avengers is yellow).
Green: This is the color of balance and growth. Though it can also be a sign of jealousy/envy.
Blue: Tranquility, trust, and peace. Some rooms are painted this color to help people feel calm.
Purple: Imagination (both creative or impractical)
Pink: Unconditional love as well as immature and girlish
Brown: Down-to-earth, protection, and comfort
White: Purity, innocence, completion
Black: Mystery, secrecy
Keep in mind, this is one person's view of color, but it seems pretty universal in other studies (though with some minor differences).
How do these colors come to play in stories?
Good vs Evil
Let's start with Star Wars. Generally the Jedi Knights wear white/beige clothing while the Sith are dressed all in black. As a character slips to the dark side, their clothing color seems to change (ie Anakin Skywalker). Of course, it can be argued that Luke was wearing black at the beginning of Return of the Jedi, so was that meant to throw us off or hint that perhaps Luke could still slip to the dark side?
Their lightsabers, as well, seem to play a part in good vs evil. Jedi wield green (growth) and blue (peace) lightsabers while the Sith use red (anger).
When we're told stories, it's not uncommon for the good character to wear white clothing to represent purity while the villain is cloaked in black/darkness. Obviously this has led to discussions about how this just reinforces racism (white = good, black = bad). So some writers have tried to move away from this trope. Or, so-called bad characters are starting to have redeeming stories told about them (ie. the film Maleficent).
Color and World Building
Color also plays a big part in world building, as some societies are built directly around color. Let's address Avatar: The Last Airbender. Each of the nations (earth, fire, water, air) have different colors to denote their different kingdoms. Earth Kingdom wears brown, yellow, and green. Water Tribe wears blue, purple, and white. Air Nomads wear orange and yellow. The Fire Nation wears primarily red, brown, and black. They each have their own distinct color, and it works well with what we've learned about what the colors mean. Green/growth and brown/down-to-earth seems very fitting for the Earth Kingdom. Blue/peace, purple/imagination, and white/purity works well for the Water Tribe, while red/anger and black/mystery embodies the Fire Nation.
The world of Harry Potter does this with the houses as well. Gryffindor is red and gold. Ravenclaw is blue and bronze. Slytherin is green and silver. And Hufflepuff is yellow and black.
Star Trek also plays around with colors. Now, each ship or generation kind of varies their uniforms, but in general blue = sciences, yellow = command, red = you have a death wish. But in all seriousness, if you look at articles about Star Trek like "The Take" you'll find that every person wore a specific uniform designated to their station. Unfortunately, the red shirts just often went down to the planet and never came back.
Colors can also be used to foreshadow events, or show a character's progression or regression mentally. The big example I'm going to use is from Season 8 of Game of Thrones. You can skip ahead if you haven't seen the season yet and don't want spoilers.
***Begin GOT Spoiler****
In the case of Daenerys Targaryen, her color scheme changes drastically along with her mentality. In Episode 1, she wears pure white clothing. She is in the north, with her lover, ready to fight a battle to save the people. She still has her best friend, her mentor, and her two dragons. Her intentions are pure. Between episodes 2-4, her white clothing takes on red lines. They just fought a battle and she watched someone she cared for deeply die before her eyes. Not only that, she starts to realize she doesn't have the support of the people like Jon Snow. Then she loses her best friend and another one of her dragons. Episodes 5 and 6, her clothing shifts to red and black during the burning of King's Landing and her ascension to the throne. In previous seasons, she had mostly worn white, blue, and browns (purity, peace, down-to-earth), and in the end, she goes mad while wearing red (anger) and black (mystery). It was a beautiful, though tragic event, of what was to come.
***End GOT Spoiler***
Another element of foreshadowing comes, again, from Star Wars. When Anakin first starts his training, he's in the traditional white or brown Jedi garb. But as the story progresses, and he starts to slip towards the dark side, his clothing changes to black. The last time we see him whole, he's fighting in black attire against Obi-Wan in white. After that, he's left in his Darth Vader suit just so he can survive. We watched through color as he slipped away from the light to darkness.
These are just a few reasons why you might consider using colors in your story. For lack of better words, you paint a broader and more beautiful picture of your world when you add in these elements. From color meanings, to symbolism and foreshadowing, there's so much you can play with.