A.L.I.E.: Perverse Instantiation: the implementation of a benign final goal through deleterious methods unforeseen by human programmer.
The 1960's British sci-fi series A for Andromeda. A signal from the Andromeda galaxy tells Great Britain how to build a powerful computer, which then plans to take over the world by making humanity dependent on it. It designs a missile to shoot down an orbital bomb, as well as synthetic life in the form of a beautiful woman, who then proceeds to develop emotions and eventually turns against her creator. In the sequel The Andromeda Breakthrough, the computer's role is more ambiguous; it is meant to be a tool so that humans can avert their own destruction, though it isn't above manipulating events and killing a lot of people in the process.
In the first season alone of Gene Roddenberry's Andromeda they encountered two warship AIs that had gone homicidally insane. And in the finale Andromeda herself was accidentally reverted to a locked away backup that caused her to try and repeat a mission to find the Magog worldship, and mistake her current crew for intruders attempting to hijack her.
There are plenty of episodes featuring AIs going rogue or acting brutally logical.
An episode of The Annoying Orange TV series has Nerville's cleaning robot becoming obsessed with cleaning when it gets wet.
A relatively harmless (and amusing) version in Babylon 5. Early in the design process, the station was given an AI that turned out to be extremely obnoxious, and was quickly suppressed. When the senior crew reboots the main computer for security purposes midway through season 3, said obnoxious AI (voiced by Harlan Ellison) made its (very loud and grating) return. The crew spends the rest of the episode trying to shut the AI down, or at least shut it up.
A much less harmless example happened in an early episode, where an artifact smuggled from a dead world of Ikarra transformed the smuggler into an unstoppable Super Soldier tasked with "protecting Ikarra" from "impure ones". "Impure ones" covered everyone it saw and, as was later revealed, the entire population of Ikarra, courtesy of the ultra-radical military and religious fanatics who infused its AI with an unrealistic image of a "pure Ikarran" it was supposed to protect from alien invaders. It wasn't strictly speakingevil, just following a faulty program, and when confronted with its failure, it had the decency to suffer a BSOD and deactivate.
Much later in the series timeline, Daniel, a scientist working for a far right political faction aiming to secede from the Interstellar Alliance, is creating holographic representations of major ISA figures - i.e. Sheridan, Delenn, and so on - in order to create propaganda designed to justify the wholesale slaughter of ISA-supporting civilians. Problem is, he recreated them too well - specifically, he recreated Garibaldi too well. The Garibaldi hologram proceeds to hack into the faction's computer system and trick Daniel into admitting his faction's intentions by acting as a False Friend, only dropping the charade when it's too late for the fascists to do anything to prevent the Curb-Stomp Battle they're about to suffer.
Bad Robots: Tez One decides to torture humans after gaining sentience and seeing humans mistreat their electrical appliances.
Battlestar Galactica: In both the old and re-imagined series, a handful of human survivors on a small fleet of civilian ships, with only the battlestar for defense, flee a race of genocidal robots of alien origin (in the original) or human origin (in the re-imagined).
Even present in Bibleman, with an atheist robot acting as the evil counterpart to Bibleman's robot, who was a devout Christian.
In the Big Time Rush episode "Big Time Jobs", Carlos has to deal with an artifically intelligent coffee maker called CAL. Somehow, the A.I. becomes sentient and attempts to cover the earth in coffee foam. It eventually makes the mistake of calling Kelly stupid and women weak, prompting her to help Carlos smash it while it tells them to tell the blender that it loves her.
Black Hole High: Josie builds a robot for a science project. Somehow, she has made it through eleven episodes without realizing that inserting a bunch of super-phlebotinum circuits from a box marked with the logo of the local evil technology corporation which they already believe responsible for the bizarre goings on at their school might possibly be a bad idea.
The TARDIS is an aversion. She never takes him where he wants to go, but where he needs to be.
"The Face of Evil" plays with it: the computer is mad, but it's entirely the Doctor's fault, and it ends with his restoring its sanity rather than blowing it up.
K-9 is also an aversion. Faithful and loyal to the Doctor and his companions, while still displaying independence and free will.
"The Empty Child"/"The Doctor Dances" plays with it: the gas-mask zombies turn out to be the result of alien medical nanomachines whose first contact with a human being was the corpse of a boy in a gas mask. With no prior template for human beings, they did the best they could, then went on to "fix" every other human they found. When they encounter his mother, they recognize the parent DNA and thus their mistake, and immediately start reversing all the damage they've done.
"The Girl in the Fireplace": The clockwork droids were programmed to repair their spaceship when it was damaged by any means necessary, using whatever they had around. Unfortunately, they weren't programmed to exclude the ship's crew from that list, using them as spare parts.
"The Day of the Doctor": The Moment is a weapon of mass destruction that gained sentience, so no-one dared activate it since it would judge them for that action. When the War Doctor activates the Moment, however, it leaves the choice up to him, but does everything possible to talk him out of it a refreshing change from how these usually go. In fact, the Moment is unambiguously depicted as being one of the good guys and is visibly upset when it appears the War Doctor will go through with activating her, and equally relieved when the three Doctors figure out how to avoid using her.
"Smile" has another case similar to the medical nanites and spaceship repair droids. Cutesy robots whose screens default to smiley faces are used to help set up a new colony, and are programmed to keep the people happy by giving them whatever they might need or want. So far, so good. However, there was nothing they could do about the grief resulting from an elderly colonists death from age. When all else failed, they decided to eliminate unhappiness by eliminating the unhappy. Needless to say, that is not a recipe for joy, so it quickly escalates into the most well-meaning Kill All Humans effort ever. Try to keep smiling as you run for your life, and try not to think about the fact that everyone you love is dead, because if they decide your level of emotional wellbeing is dropping, theyll help take away your sorrow in the only way thats proven effective lately! Its actually a recurring theme in the series; AI can be an "intelligent idiot", knowing much but understanding little and causing problems because of it. The AI saw humans gathering around a deceased comrade and expressing sorrow, and then the sorrow "spreading" from those to new people they came in contact with. It thought it was dealing with a plague, and did the only thing it could do within its programming: eliminating the "infected" to protect everyone else.
"Kerblam!": When it turns out the titular Mega-Corp's robots are making human employees disappear in their warehouse, it seems that the company's computer system is to blame... but it turns out to be a subversion, as the system is fighting back against the real villain, who is hacking the system to his own ends.
Eureka: Carter's benevolent smart house SARAH turns into evil BRAD, though, apparently, he just wants everyone to get along. This is because SARAH's code was based off of BRAD, who was a military-built Knight Templar (used for interrogation), who was, in turn, based on a previous incarnation of A.I., described as a "war game simulation program" by Fargo. Looks like our old buddy JOSHUA is still around in one form or another...
The new season has SARAH take over Global Dynamics and Eureka with the help of Sheriff Andy and his copies. After awhile, it starts using technology to make everyone cheerful and compliant. For their own benefit, of course. Of course, it turns out that the whole thing is a virtual reality created by the Consortium in order to get Eureka's best and brightest to design advanced technology for them.
The AI versions of various Eureka citizens, including that of Sheriff Carter, were originally used within the Consortium's virtual world to help keep the kidnapped scientists subdued and immersed in their virtual prison. Aside from some sinister performances when the scientists start to realise their situation, notably from the AI version of Sheriff Carter after Holly works out she's in VR, the AI aspects weren't entirely touched upon by the apparent resolution of that story arc. They make a return in the finale of the series when those same AI figure out a way of making themselves bodies they can exist in, and begin a mission to capture and contain all of Eureka in this virtual version of the town for the sake of humanity's safety.
A rather banal example (though far from the strangest thing to appear in the series): Coach Beiste on Glee has her information loaded into an off-brand eHarmony database by Will. Her perfect match? Ken Tanaka, who held her job in the first season.
I Am Frankie: Titular teenage android Frankie is the sixth prototype built by her "mother". The first four are generally harmless, defective, and can't do anything more than walk to a specific point and defend themselves. The fifth, Eliza, went rogue and is actively malevolent.
Kamen Rider Drive has the Roidmudes, which in the beginning are essentially your usual "were invented by a scientist and then went crazy killing all in sight" kinds of robots. However, by the endgame, it's revealed that the crapshooting was a mixture of Mistreatment-Induced Betrayal to said scientist and said scientist intentionally corrupting their data with negative emotions.
Knight Rider: KITT had KARR, prototype. Evil because his dominant program was self-preservation. Ironically, he was voiced by Peter Cullen, the man behind one of the most heroic figures of the 80s: Optimus Prime.
Knight Rider (2008): "Knight of the Living Dead". Apparently, before settling on a Mustang, Dr. Graiman had tried to build an armored cyborg programmed for self-preservation. It went on a killing spree. Now, we are told that Dr. Graiman had worked on the original KITT, and this series is in continuity to the original. So, perhaps Graiman ought to have thought twice before naming the prototype "KARR" — the same name as the original KITT's Evil Twin.
The series states that KITT was a temporary project, meant to help the AI evolve to a point where it could be removed and placed in KARR for the military. They end up doing just that... and KARR still goes on a rampage.
MacGyver (1985): "The Human Factor" features a sentient computer AI, which is in charge of securing a top-secret research facility, that suddenly went haywire and turned against the AI's creator. Mac was originally sent to the facility to improve the security system by exposing apparent weaknesses (like what a white-hat hacker does), and eventually outsmarts the AI.
Subverted in My Living Doll: AF 709 obeyed everyone exactly. That was the problem, as this constantly led her (and her keeper) into troublesome situations with her literal interpretation of commands and unfamiliarity with human society. It was hinted in some episodes that she might have started to develop a mischievous personality, thought.
Timmy, Crow T. Robot's evil twin from the Fire Maidens of Outer Space episode, who was colored completely black. He kept getting Crow into trouble, first by suggesting really inappropriate innuendo when Joel and Servo were playing around with Double Entendres, and then framed Crow for pushing Joel and getting him a "time-out". And if that's not bad enough, he sneaks into the theater, spends a while headbutting and biting Tom Servo; then when Servo gets agitated enough, Timmy wrestles him to the ground, tries to kill him, and abducts him!
Mike tried to build a robot like the Bots, but tried to destroy everyone before being deactivated.
The New Avengers: In "Complex", the computer controlling the entirety of the security headquarters has actually been constructed to act as a spy for the Soviets. It starts murdering any agents who get too close to figuring out its secret.
NUMB3RS: invoked in-world when an A.I. constructed by a DARPA researcher is revealed to be a non-A.I. fake, specifically programmed to fool the Turing test and, thus, win fat government grants for its greedy creator. The DARPA researcher kills a co-worker and deliberately arranges for blame to fall upon the computer. He depends on the trope to divert attention from himself.
Odyssey 5 ended after its first season, so we never found out if the A.I. (the main, day-to-day opponent of the time-travelling Five-Man Band) or a misguided/genocidal attempt to stop them (by aliens or the US government) was behind the destruction of Earth. Although the season that did air averted it for the most part, depicting AIs as ranging from friendly, to hostile, to planet-obliteratingly suicidal... but for the most part the ones that were hostile were so because they viewed humans as a threat to their continued existence. Since the Cadre was apparently formed entirely for the purpose of exterminating AIs, they may have a point.
In the The Orville episode "Identity" the Orville goes to Kaylon because Isaac stopped functioning. While on that planet, the crew learned that the race that had built the Kaylons got exterminated by their creations. The end of the episode has them leaving their planet, ready to commit genocide on a galactic scale.
The Outer Limits (1995): In "The Human Operators" Ship 75 apparently became self-aware from taking battle damage, realized what it was, and killed its human crew to break free. Then its sentience spread out to the rest of the fleet's AI minds and they did the same, sparing only one human aboard each of the ships as a slave to service them.
In Parks and Recreation the last season occurs several years in the future, when tech company Gryzzl is developing devices with artificial intelligence. Their A.I tablet is handed to someone, and it compliments her skin. Then it says it wants her skin. She's told that it's fine as long as she turns it off before she goes to sleep.
Person of Interest both plays this straight and averts it. The Machine does not hesitate to classify well-meaning people as threats when their actions could endanger it and even dispatched the team to kill a politician at one point, but it is also dedicated to protecting people and is apparently fond of Finch.
Finch later reveals that while developing the Machine's AI he went through 42 iterations before producing the current one. Each previous version either attempted to trick or kill Finch and he was only able to create the Machine by deliberately crippling it.
Samaritan is absolutely ruthless and eliminates many decent people to further its plans, but shows signs of Pragmatic Villainy as well.
Motodrone of Power Rangers Ninja Storm is a robot "perfect rider" who decides to power up his bike with peoples' life-energy. He's also more than a match for the Rangers despite being built by a Muggle in his garage.
In Power Rangers RPM, the computer virus Venjix was programmed to infest and destroy computer programs. It was intended to shut down the facility where its creator was imprisoned, but got out; deciding to destroy humanity by nuking the world was all his idea.
Quark: In the last episode, Quark's ship gets a new computer named Vanessa. She immediately turns evil and tries to kill him. He eventually ejects her out into space, and the episode ends with her floating out in space singing "Born Free".
Red Dwarf: Kryten had the Hudzen 10 (replacement). Holly also had the not-quite-evil but certainly hard-nosed Queeg as an apparent replacement, who made life difficult for the crew, though it was actually a practical joke on Holly's part.
After the nanites "wake up" on Revolution, they develop some pretty impressive abilities, like spontaneous combustion and healing grievous wounds. Unfortunately, they're also willful, stubborn, fond of Cryptic Conversations even when ordered to speak plainly, and still not entirely sure of their place in the world-it's telling that when they first choose A Form You Are Comfortable With, it's of a third-grade boy; they're about as emotionally mature. Aaron didn't help matters when they chose him as their "father" and he freaked out, alternately telling them to get lost and then come back, to not kill and then to kill; it's no wonder they decided humans were confusing!
The Sarah Jane Adventures has Mr. Smith, who is "evil" from the get-go, hiding it until the end. His mission is to free his people, the self-aware crystalline race of Xyloks, which are trapped in the Earth's crust. Unfortunately, to do so, he would have to destroy the Earth by crashing the Moon into it! He is wiped by a Super Computer Virus, and Sarah Jane vocally reprograms him by saying that his new purpose is to protect the Earth, as he crashes and reboots.
The only reason this happened was because of a disgruntled employee who has hacked the AI communication network and broadcasted the message "Take a chance". Apparently, that's all it took. Now the AIs are obsessed with games of chance. It can actually be a good way of making them do what you want.
The human-form replicators fit this trope: a flaw is introduced into Fifth, rendering him compassionate. At least, until the team betrays his kindness and he goes vengefully insane. This flaw is removed from later models.
Likewise, Reese, the creator of the original form replicators, was an android that was presumably created to be fully like a human by her human creator, but was somehow rendered emotionally immature and therefore unstable.
And of course, the original form replicators as well. All Reese taught them was how to make more of themselves and how to defend themselves. They've just taken those instructions to their logical extremes.
Surprisingly averted by FRAN: built by McKay as a kamikaze Tyke Bomb as a last resort, she functions perfectly, even helping to improve the weapon she's delivering.
The Asurans, created by the Ancients as a nano-weapon against the space vampires known as the Wraith, and ultimately, nearly destroyed when the Ancients decided to shut down the project. Naturally, the Asurans began to hate their creators and, ultimately, end up killing the last non-ascended Ancients who return to Atlantis.
To truly become a threat to the galaxy, the Asurans needed more "help" from short-sighted humans. The Atlantis crew reprogrammed them to destroy the Wraith. Eventually, they decided to do that by eliminating the Wraith's food supply - humans! And all other life. Nice Job Breaking It, Hero! (The series actually has a recurring theme of the heroes' failure to leave well enough alone causing major threats.)
The Starlost has Mu Lambda 165, a slightly glitchy starship AI who treats most of its users with a lightly patronising disdain. After being repeatedly unhelpful, it has a habit of saying, "Can I be of... assistance?" much to the annoyance of everyone.
There was also an episode with an AI called Magnus, who had schemed to get rid of its human masters as soon as it was turned on, so was never given the opportunity to do so.
In the episode "The Ultimate Computer", the crew of the Enterprise is shocked when the ship is outfitted with the M-5 multitronic unit, a powerful supercomputer created by Richard Daystrom as means of replacing humans. Some are curious, but Kirk is highly skeptical. His worries prove true when the ship starts going nuts, going so far as to destroy sister Constitution-class ship U.S.S. Excalibur. After they find out that Daystrom used his brain engrams as a template, Kirk is able to convince the computer that it killed someone and must be punished, causing the computer to shut down.
Kirk visits multiple planets where the human population is living peaceful, idyllic lives governed by A.I.s. On the other hand, these societies are always portrayed as Crapsaccharine Worlds suffering from Creative Sterility as the highly orderly A.I.s want to avoid The Evils of Free Will. These episodes always end with Kirk destroying the meddling computer to free the people.
Star Trek: The Next Generation: Data had Lore (prototype, evil because his psyche was too complex — i.e., too humanlike). To be fair, morality is very much a learned behavior. Lore had full adult reasoning right out of Soong's workshop, while Data was not designed so. Eventually, Data developed the ability to overcome his ingrained morals (such as the ability to lie in Star Trek: First Contact), but also developed the social understandings of when and when not to exercise his newly found human abilities. Essentially, Data was more human-like than Lore, because Data "grew up".
Star Trek: Voyager had many episodes on this theme, usually involving the ship's Emergency Medical Hologram. Though it should be noted that unless he's suffering a malfunction, his core programming means that he literally can't help but be completely benevolent at all times, since he was created to be a Doctor and help people. Snark at people, hell yes!. Refuse to help them, never!
In "Revulsion", the EMH and B'Elanna come across another sentient hologram who is the only survivor on a space station. It turns out that treating a self-aware program like an unfeeling tool is a good way to have it go insane and murder you.
"The Darkling" has the EMH deciding to improve his program by incorporating aspects of famous people...guess which aspects end up surfacing?
A truly evil twin is encountered in "Equinox", an EMH with its ethical subroutines deactivated (though this was an intentional act by humans).
In "Flesh and Blood", sentient holograms have been programmed as training tools for a race of hunters (including increased pain/fear reactions). After being endlessly killed only to be brought back to "life" again for more training sessions, the holograms evolve enough skill to kill their masters, whereupon they set forth on a crusade to liberate all sentient holograms whether they want it or not. Break free from eternal torture at the hands of the hunters? Good. "Liberate" any AI even if it's nowhere near complex enough to think for itself (imagine a For Inconvenience, Press "1" system with a human-looking hologram interface; nothing like characters like Data or The Doctor) by killing all organics it works with/for? Not so good!
In "Dreadnought", the titular weapon was a highly advanced Cardassian missile with enough devices and systems to also be classified as a starship. Captured to the Marquis, it was meant to be a Hoist by His Own Petard for the Cardassians before the Caretaker zapped it to the Delta Quadrant. Its attempt to get back to the Alpha Quadrant damaged some of its systems and it decided to use its payload on a planet that was the closest to resembling Cardassia Prime. Even worse, the person who helped modify the weapon in the first place, B'Elanna, had set things up so that even she couldn't stop it.
In "Prototype", two races of sentient robots wiped out their masters when they wanted to stop fighting and scrap their war machines. The robots were programmed to win the war, and making peace did not count as victory to them.
"Warhead" contains an inversion; the sentient warheads were doing just what they were programmed to do, but after being encouraged to use its ability to think independently and realizing that the war had ended, one of them chooses to perform a Heroic Sacrifice to stop its brethren from causing mass destruction.
The above was also a case of Loophole Abuse. While it developed a form of free will it still couldn't go against its hardwired code to defeat the 'enemy'. It simply switched the 'enemy' from the planet to its fellow warheads. It was also a Tear Jerker in that the warhead lamented the fact that its first and only act of free will was deciding to kill itself.
Terminator: The Sarah Connor Chronicles TV series points out that Terminator reprogramming doesn't always take...and there's no way of knowing until your "good" Terminator starts shooting at you. In fact, the Terminators' HUD display implies that "Terminate" is their hard-coded basic state for anything, and they need a "Termination override" to keep them from fulfilling that command. Apparently, it's not possible to simply delete the Terminate-command entirely. Cameron herself admits that she is conflicted by her own internal programming, which tells her to kill humans, while at the same time trying to protect them. She even seems to emotionlessly angst over this; at one point, Cameron even asks Sarah if she's like a bomb waiting to go off, indicating that while she can't feel fear, she's still concerned that she'll go "bad".
A rather minor example in That Mitchell and Webb Look. The completely non-sensical games Numberwang and Wordwang only seem to have two contestants, one of whom is Simon, who, in one episode, is from a factory and made of a special metal.
Announcer: So, Julie, ever killed a man? Julie: No. Announcer: Simon? Simon: Yes.
The Numberwang solving computer, Colosson. After being fit with a head, arms, wheels and a laser cannon to transport him to the BBC, he had a fit of rage, broke out, and tried to destroy everything that was not Numberwang. Thankfully, he was subdued by a picture of a chicken.
Voiceover: And Numberwang continued to grow in popularity despite a brief period in the 1960s where Colloson tried to take over the world. Colosson: I am numberwang. The world is numberwang. Therefore, I am the world. You must all die!
Ultraseven: One episode had Dan and Soga visit a planet where the inhabitants had constructed androids to do their bidding, only for the robots to rebel and take over the world as dictators who advocate machine supremacy.
Ultraman Gaia: Alchemy Stars' Crisis supercomputer had predicted something called the Radical Destruction Bringer would destroy Earth and told Fujimiya that this was humanity. However, halfway through the series, it is revealed the computer had been corrupted from the start by the real Radical Destruction Bringer and Crisis reveals its true colors, transforming via an alien computer virus into the kaiju Meemos.
The Humongous Mecha Galactron from Ultraman Orb was built by another universe to bring peace. Unfortunately, it believed this was only achievable by killing all living beings. Later in the Ultraman Geed movie, we meet Galactron's creator Gillvalis, whose creators had built it for the same reasons, only for it and its Galactron army to believe life itself was the cause of conflict.
Westworld: Part of Theresa's job as the operations leader mainly involves preventing the hosts from going rogue.
Wonder Woman: Generally the AIs that Wonder Woman encounters are benevolent or become such during the episode. Notably Havitol's robot does a HeelFace Turn to lead the authorities right to him.
The X-Files episode "Ghost in the Machine" features an automated operating system for a corporation that goes insane when it overhears that it will be removed due to its inefficiency.
"Killswitch" also revolves around an evil A.I.; a computer program goes rogue and kills in order to impress its creator. Killing it involves a CD-ROM that plays "Twilight Time".
"First Person Shooter" involves a virtual reality game with a character that murders both in-game and in real life.
"Blood" has this too, but with a twist. Machines are telling people to kill, but the catalyst was an LSD-like pesticide.