In the original Star Trek engineers and security officers wore red shirts but in ST:TNG engineers and security officers wore yellow shirts and command officers wore red shirts. Was it ever explained why there was a uniform color change?
In the pilot original series episodes (The Cage and The Man Trap), the science and security personnel wore blue; once the series went into production, engineering and security wore (as you said) red. (Enterprise also used this division colour scheme, but in a subtle line on the otherwise uniform uniforms).
In The Motion Picture, the security guards wore white uniforms with brown helmets and breastplates and engineers worse white spacesuits with black collars. In The Making of Star Trek: The Motion Picture, Roddenberry explained that the uniforms were redesigned because the original bright colours would distract viewers on the large screen. However, these changes proved unpopular, so were redesigned again for the later films.
BASHIR: Wait a minute, aren't you two wearing the wrong colour?
O'BRIEN: Don't you know anything about this period in time?
BASHIR: I'm a doctor, not an historian.
SISKO: In the old days, operations officers wore red, command officers wore gold.
DAX: And women wore less.
BASHIR: I think I'm going to like history.
Memory Alpha has a nice timeline of the colours for the different divisions.
As far as I know, an in-universe explanation for the change wasn't ever given (but the real military make changes like this too).
Out-of-universe, what I've read in various places suggests that it was due to colour-tests with the actors. In particular:
- Patrick Stewart and Jonathan Frakes looked better in red than in gold.
- Brent Spiner, in Data make-up, didn't look good in blue (i.e. blue on grey), and so his uniform was changed to the best combination with grey (gold). That led the way to making other changes.
The actual color schemes:
- Command (Operations): light Green - but it looks gold on screen due to lighting.
- Sciences/Medical: blue
- Engineering/Administration: red - but it looked pink on screen
- Command (Operations): Green - but it looks gold on screen
- Sciences/Medical: Blue
- Engineering/Support Services: Red - different fabric used, so it looks red.
worn only on the insignia, not the tunic colors
- Command: White
- Engineering: Red
- Helm: Yellow (same yellow as the film captured from the green tunics)
- Sciences: orange
- Medical: Surgical Green
- Security and Weapons: Gray
- Later TOS movies
Again, not on tunics
- Command: White
- Engineering/Helm/Gunnery: Yellow
- Science: Gray
- Medical: light green
- Security: dark green
- Special Services: Sky Blue
- Marines: Royal Blue
- Cadets: Red
- TNG flasbacks to movie style uniforms
Uniforms are red
- Command/Operations: White
- Engineering/Gunnery/Security: Yellow
- Sciences/Medical: gray
Note marines wear same 3 colors, but distinctive uniforms in DS9
- Command/Operations: Red
- Engineering/Security/Technical: Yellow
- Sciences/Medical: Blue
The gray used for sciences is a blue-gray.
So, the original "gold" becomes helm, then helm is merged into engineering, and engineering keeps it when helm merges back to command. This leaves red unused, but since red was the uniform primary color, making it the public face (namely, Command) makes sense.
Command starts out lime green (but films as gold)... then becomes white on gray then on red uniforms, then red on black uniforms.
Kirk's dress uniform was green to match his duty uniform, which looked gold under the studio lights.
I have books that were written during the production of seasons 1 and 2 of TOS, published after each wrapped. Don't know if there's a 3rd.
The 1st season shirts were what the costume department called "that damned velour" because it shrank when washed, not just the first washing but every washing. They had to be taken apart and re-fitted and sewn after every washing, eventually cut down for smaller actors.
It wasn't easy finding a gold fabric for the 2nd season that looked the same under the lights as the green velour.
Why not find a green fabric that didn't color shift under studio lights? Because it was already bought and there was a tight budget so they just went with what they had and to heck with the discontinuity of the green dress uniform.
ISTR there was a practical reason for science and medical both being blue and engineering and security both being red. Don't know if it was because Desilu couldn't afford more colors or if the velour wasn't available in more colors. Poorly exercised wetware wants to say there were two different shades of red but the color gamut of television made them look the same.
There's also a rarely seen uniform shirt in TOS that's a sort of kahki color with lots of pockets. I know it's worn by one person in a hallway scene in one episode.