Composers don't score to the script, they score to the rough cut of the film. There's no way the script would give them the information they needed about timing, mood, and the like. Generally the composer sits down with the producer or director for a spotting session -- going through the rough cut, deciding which scenes should be scored and which shouldn't, figuring out the timings, discussing the desired mood and musical approach, and so forth -- and then goes off and writes the score.
As for why some of the weaker episodes like "Spock's Brain" or "And the Children Shall Lead" evoked such lush scores, part of a composer's job is to fill in the gaps -- to convey the aspects of a scene's mood and meaning that don't come across in the dialogue and visuals alone. So compensating for what isn't there is already part of the composer's job. The weaker the episode, the more the score has to carry it.