The art of the pixel is to use as little colours as possible, and get the same or better result than what could be done with more colours. This is not true always,but was a must back in the days of colour selection(old consoles, like gameboy colour and so on had these restrictions), but this is also a good starting point for beginners as it teaches that person "how" to pick his pallet to get the most of it.
As for selecting colours, I usually put random colours in as a place holder and then change as I go. However this is me, and a few people choose to developer or us a pallet they made or already exists.
If you you go to the "Things of Importance and Interest" part of this site, there are very helpful topics and links to other topics to read up on that will change your understanding within one read, but remember things take time, and you learn by practice.
Now I feel bored. Nice to see programmer here. Sounds like future Indie'ness
Edit:
Reading your post again, here are things you should look up to help your understanding.
Find the definition of "HUE", "SATURATION" and "BRIGHTNESS". As these are very usefull to know when picking colours.
On this site there is also a topic about colour theory(again "Things of Importance and Interest" section), that has helped me and others so much.
There are many more and I hope they help you