That's true; Kirk's obligation to defend his ship and his crew made it a battle for survival rather than a moral debate.
What happened to dying for the king and country? In "Omega Glory", Kirk swore that "A star captain's most solemn oath is that he will give his life, even his entire crew, rather than violate the Prime Directive."
That's a classic problem, really. Patton had it all wrong: sometimes wars are won by dying for one's country, rather than by staying alive. A soldier may do damage to his nation's reputation or strategic aims by fighting for his life, whereas letting oneself be killed would preserve said reputation or allow a strategic plan to proceed. Yet such a requirement for self-sacrifice cannot be written into the doctrines, because the soldiers wouldn't follow their commanders if they were told that.
In "Omega Glory", Tracey fought back an aggressive army of attackers who would have taken his life, plus those of thousands of others, and Kirk considered that vile. In "The Apple", Kirk fought back a machine that threatened nobody but him and his crew, and saw nothing wrong with it. What was the difference? That killing the machine wasn't directly comparable to killing live natives? But Kirk could see the causal connection that the machine kept these natives alive...
Self-defense was probably a criminal act in both cases as such. But Kirk could argue that he'd fix things later, before any biological lives were lost; Tracey's victims stayed dead. And there's every indication that Kirk or Starfleet did return. Remember what got them there in the first place? Starfleet wanted to contact the natives about the strange and alarming readings that (as we later learned) Vaal was responsible for, presumably to fix things for the natives. Kirk fixed them halfway; Starfleet would be interested in fixing them the rest of the way. And perhaps gaining colonization rights on the Garden of Eden.
Timo Saloniemi