Because it's a TV show?
The characters really look like idiots there. Several plots had already featured heroes and villains sabotaging key areas of the ship, sometimes even when those were guarded by live personnel, and when the saboteurs had little experience (say, Khan). Going to Main Engineering was rarely necessary for this, and Main Engineering appeared to be the only place where M-5 was able to defend itself. Did Spock and Scotty suffer from memory problems or what?
(I can only assume the heroes did not want to do anything too destructive at that point because they knew M-5 was an expensive item that Starfleet would prefer returned more or less intact. Lives were only at stake some time later in the episode.)
Also, communicating with the other starships should not have been that complex. If subspace radio was out, Kirk could have asked Scotty to send an SOS with running lights, or in a dozen other ways M-5 wouldn't think of. Sure, the computer was supposed to be versed in Starfleet practices - but Kirk's known forte was thinking outside the box. Surely he could have outthought this particular box of circuits, too, without needing to directly confront it?