Why is it important to have few colors in a palette
A few words come to mind:
Combination
Control
Meaning
CombinationArt is a visual language.
Let's explore other languages that exist.
WordsThe English alphabet contains 26 letters.
ABCDEFGHIJKLMNOPQRSTUVWXYZ
In combination they can create infinite words.
Different combinations of letters have different meanings.
We do not need every letter to express a single thing.
ProgrammingThe C programming language has 32 keywords:
int, float, double, struct, if, else, void, const, etc.
In combination we can write infinite amounts of software that do whatever we want.
How the components of the program are structured is a choice.
NumbersIn the base 10 number system there is:
0123456789
However there are other number systems.
Such as Hexadecimal which contains:
0123456789ABCDEF
And Binary:
01
Combinations of these can produce infinite numbers and even the same numbers (to a certain degree of error in the case of floating point numbers).
Depending on what we need to do, something as simple as binary can be much better suited to our needs than base 10.
FoodDifferent pizzas have different toppings:

Combinations of ingredients create different flavors.
By limiting the number of toppings we can create a more specific taste.
Of course EVERY topping is also a taste.
They also naturally create different balances of color.
ColorA common way to look at color is the combination of 3 components:
Hue, Saturation, and Luminance.
With different combinations of these we can make a crapload of different colors.
But the colors themselves can be used to draw infinite images.
Or even the same image with different combinations of colors.
A generic example is, we can draw a Green dragon, a Red dragon, a Blue dragon, a Yellow dragon etc:

No matter the color he is still a dragon.
ControlProcessIn interest of saving me some time:
Read this.And this.Photoshop has similar features I assume but I am not as familiar with them.
Look thru the documentation or find another source.
CompositionWe can control images and how they are perceived thru the use of composition tools and techniques.
One of the many is color.
With color we can control eye movement.
Re using colors in different areas lets the viewer's eye flow around the image easily
On my doodle (which is nothing special at all) I had this in mind:

Even a character is a composition.
Much better examples exist.
Game CodeImage data can be manipulated to do cool stuff.
Many visual fx in games use colors as data to create different fx.
The code that does this is called Shaders.
Colors can be stored as a data type called float4.
It contains 4 values in a group that range from 0-1.
Like this: color(r,g,b,a).
It's a massive topic and I'm not going to cover it here.
But realize it can be important because some code might be expecting certain colors to use as data.
MeaningColors have meaning.
These meanings can change depending on context, purpose, culture, expectation, and even someone just saying this = that.
By narrowing or widening the color range we can create different meanings.
Some common examples are:
Time of DayMorning, Noon, Evening, Night:
SeasonSpring, Summer, Autumn, Winter:
ElementsI'm out of time to create an original example for this.
There's plenty of examples elsewhere.
CharactersWith the use of color the exact same sprite can perceived as a different character:
CountriesUSA, Japan, Germany, Brazil:

The flags are not mine.
Grabbed them from here.The crappy palette edits of your scene are not intended to be examples of good color choice.
They are meant to show change in color is perceived as different.
You can do much better.
So... What?There's an amazing amount of other things that can be considered.
Covering them all in extreme depth is outside the scope of this post.
I can recommend this old book as a general source of good information.There are many other sources out there, perhaps better and even free ones on the internet.
Search around.
The idea here is not to bog you down with theory.
Just realize that colors are tools used to convey information.
What are you trying to tell the viewer?
Do you need 7,000 colors to tell them that?
Or is it possible to tell them in only 64?
32?
16?
8?
2?
In all art forms the answer to every question is always "It depends".
Mess around and see what happens.