K9 is using the STM to try and rectify his memory loss of events prior to his arrival and regeneration. Gryffen and Starkey discover him linked to the machine, which creates a feed-back, and K9 loses all control of his memory and programming. He becomes a danger to everyone and starts his self-destruct programme.
Image source: themoviedb.org