WALL•E never explains how robots, such as WALL•E and EVE, gained personalities, or why some do and some don't. It's probably better that way. WALL•E is actually insane in a good way. 700 years with no-one to interact with but a cockroach will do that. Essentially, all the character robots in the movie develop personality and emotion when they step outside of their primary directives. For some like M-O, this is a fairly short and abrupt step when he chooses to ignore the path he should be following in order to do something he wants to do (i.e. he gets annoyed enough to break a rule). For others like EVE, this is a more subtle development. Even the misfit robots in the robot infirmary aren't all depicted as insane — some just don't behave within their intended function. Of course, that raises the question of why they were programmed to be able to make decisions like that.
WALL•E did a fairly good job of justifying most of the robotic personalities, presuming that all of the robots have at least partially adaptable A.I. None of the robots (aside from possibly some of the "insane" ones) are shown outright defying their intended purpose, only selecting one path toward that purpose over the other. M-O, for example, is supposed to ensure the ship is clean, and to follow a programmed track — causing a "dilemma" when he spots dirt outside of said track. WALL•E might have had some kind of programming to recognize unusual objects and to keep track of them (not an unlikely possibility for a garbage collector robot), manifesting as "curiosity" over time, and EVE, being designed to identify signs of life, might have had some kind of "empathy" programming for this purpose. And AUTO, who commanded most of the ship bots, was just doing what he determined to be humanity's best chance for survival.
The title character in The Iron Giant. No explanation why it has a humanoid form, or why it can emulate human behavior so well.
The Terminators from the titular movies are made of human skin stretched over a robotic skeleton. As robots that are meant to infiltrate human camps and slaughter them from inside, the only thing that seems to tell them from a normal human is their Nigh-Invulnerability; putting that aside, they look, smell, sweat, bleed and walk like an actual human. Dogs, however, aren't fooled.
However, the Terminators don't act human (except the T-800 in Terminator 2, that learns things like "why humans cry", and the T-850 in the third movie, that has psychology in his programming and is thus able to do things such as lying).
There is a deleted scene in Terminator 2 (restored in the extended release) that clarifies that most Terminators have their learning switch turned off before being sent out on the field. The reason being that SkyNet fears (or whatever) the Terminators learning -too- much and becoming sentient and self-aware like itself or otherwise troublesome to control. This switch is turned on for the T-800 in the movie in the scene and thus why it was able to eventually learn such things. Assuming higher numbers mean later models, it can also be assumed that SkyNet incorporates better research into the later models - the T-1000 was much much better at being an infiltrator though it seemed to kill most anyone within a few minutes of meeting them. It maybe also that those Terminators that are on a specific mission of infiltration rather than a mission where it'll kill anything that gets in its way are given more learning time and/or directive to act human; this is suggested in the Sarah Connor Chronicles where the resident Terminator has a flashback to the time when it interrogated the human it's based on as it was intending to access a heavily defended base. Strangely, the flashback occurs because the Terminator gets hit on the head (or something) and gets amnesia.
Though it's never explained why SkyNet continually thinks like a human and keeps sending Terminators back to different points in time AFTER the first Terminator (allowing the humans to become better and better prepared) rather than sending a robot back to a point BEFORE the first Terminator appeared (thus adding the element of surprise AND less advanced technology), or just continually sending the same Terminator to the same point in time to increase the odds of the proper timeline taking place.
This can be Fanwanked away; presumably sending Terminators further backwards in time costs more resources, and as Future!John destroys more and more of Skynet, it can no longer afford to send Terminators back as far. Also, the time travel technology could have a fixed "distance" it can project an individual back in time. Lastly, the entire series could occur in a near-identical parallel universe that 'lags behind' the other by the specified number of years meaning the "time travel" discussed by the non-scientists is in fact (slightly) more plausible dimensional travel.
Ridiculously Human AI was avoided in Sunshine. Although, like HAL, the computer can respond to natural-language commands and has a creepily calm voice, it has no internal mental life to speak of and therefore doesn't anticipate or adapt to problems outside its original mission profile. If you've ever tried to wrestle a computer program into doing something beyond its basic functions, you'll see how accurate this is.
It is, however, a plot point in 2001: A Space Odyssey, in which HAL becomes paranoid and psychotic after being given conflicting commands of equal importance. (At least, that is explanation offered outside of the film for his actions.)
The problems inherent in programming ridiculously human robots is explored in A.I.: Artificial Intelligence, in which the robot David is programmed with genuine love, rather than the simulated love of previous models (like Gigolo Joe). This leads to a Pinocchio-like plot later on.
It shouldn't have, however. The original story by Brian Aldiss contained none of the "Pinocchio" subplot (and it was better). Aldiss begged Kubrick not to include the Pinocchian subplot, to no avail.
As for "regular" droids it is worth mentioning that most of them aren't programmed for personality, emotion, or human behavior. Some, like the most commonly known R2-D2 and C-3PO, develop those traits. Others don't.
Although one could argue that even common, run-of-the-mill droids have emotions. The MSE droid ran away from Chewie in terror, the droid on Cloud City was rude to Threepio for no reason, and the Gonk droid screamed in terror when being tortured in Jabba's dungeons.
Of course, astromechs and protocol droids are explicitly amongst the most intelligent droids in the Star Wars universe; it's implied that the more intelligent a droid is and the more varied a life it leads, the more prone to illogical quirks and willful independence (or developing a genuine personality, depending on your point of view) it becomes. This is why most droids are regularly memory-wiped, something again that explicitly hasn't happened to R2 or 3PO for far longer than the norm.
Talking about protocol droids... why bother making a droid designed to communicate with thousands of species look humanoid at all? Especially considering C-3PO doesn't seem all that mobile compared to other droids like R2-D2.
Because humans are explicitly the most common and widespread species in the galaxy, to the point where human physiology is generally used as the baseline standard for sentient life. Hence the use of the terms "humanoid" and "near-human" in the Star Wars universe. It therefore makes sense that droid manufacturers would design their product to appeal to the widest possible demographic.
Also, C-3PO only resembles humans in that he has 2 arms, 2 legs, and a head. This seems to apply to at least 95% of alien species as well (you might just as easily say that a protocol droid is "Wookieeoid" rather than "Humanoid").
The X-wing series also introduces perhaps the most independent of droids a 3PO unit called Squeaky. Squeaky managed to subvert its programming and steal a ship to lead an escape from the prison/spice mine planet Kessel. For his actions he was freed from any present and future ownership. By the time of the X-Wing series he has a highly developed personality that goes in contrast to the standard demeanor of most 3PO units who are programmed to be courteous and polite to everyone. Squeaky routinely insults those around him and despite being originally a translator, has worked as a bartender and later as a quartermaster for the New Republic.
It's also worth noting that there are some droids in the Star Wars universe who are so human that they've freed themselves from any obligation to humans or even any moral code of any kind, such as IG-88, a ruthless bounty hunter, or HK-47, an assassin droid who relishes his work.
Star Wars: The Old Republic goes all over the map with this. From the annoying sycophant ship droids, to the Jedi Knight's 300+ year old astromech who has Been There, Shaped History to Dr. Cedrax's "lovely assistant" (and girlfriend) Holiday, to an eccentric Jedi Knight who believes droids are just as connected to the Force as organic beings, to the entire Directive 7 Flashpoint, involving an artificial intelligence that has decided droid liberation should mean killing all humans (and a healer droid who may not like organics, but doesn't want them wiped out, either as Mission Control). But since these are the same writers who gave us Reapers and Geth, it's not surprising.
The intelligent bombs of Dark Star, most notably Bomb No. 20.
The "replicants" in Blade Runner are very difficult to distinguish from humans — it's very possible that protagonist Rick Deckard is, himself, a replicant. In fact, Ridley Scott has stated that Deckard is a replicant in at least one of the movie's two edited versions.
In fairness, the replicants are biological in nature, so it's much more plausible that their brains and minds would function as a living being's do, even if that were not their builder's stated intent. In fact, at least in Rachael's case, making them indistinguishable from humans is their builder's stated intent.
The Tyrell Corporation's slogan is, after all, More Human Than Human
Don't think of them as robots/androids at all - they are "genetically engineered" - more like the characters in The Island (2005) who are cloned humans, created to provide spare parts for the people they are cloned from. They were just "designed" to only live a few years, the idea being that they would not live long enough to develop personalities, emotions, free will, etc. As if!
Starchaser: the Legend of Orin is a huge example of this trope, as its various robot characters express just about every emotion that could possibly come up in an animated action b-movie (sarcasm, hysteria, cheering, evil laughter, frustration, indignation about being reprogrammed through circuits located in their metal asses, getting seduced by feminine robots, and so on).
Johnny Five from Short Circuit gains sentience and self-awareness after being struck with lightning. Then, after a whole night of feeding on input (reading every book in Stephanie's house, and watching TV all the while) he grows a playful, childlike personality that is filled with wonder at the world around him. Most impressive of all, he develops his own set of morals without ever being told, going as far as to reject his original purpose as a war machine and refusing to "disassemble" any other living thing (or, indeed, other robots) even when his own existence is at stake.
As Nick says in Cavemen: "Cheesy?! What exactly is cheesy about a wise-cracking robot with a heart of gold fighting the military-industrial complex?"
The notorious Andy Kaufman-Bernadette Peters comedy Heartbeeps (1981), about a pair of robots who fall in love with each other, goes to town with this concept.
In the Alien movies, the androidsScience Officer Ash, Bishop, and Analee Call all pass for human until they're "bleeding" a milk-colored Symbolic Blood. The last of those three in particular conveys so much emotion that nobody ever would've suspected she was an android. This is because she is supposedly a next-generation android that is illegally build by other androids and has to live in secrecy for fear of being discovered.
Likewise in Prometheus with David. Exploration of how human he really IS forms the heart of his character: though he's not supposed to be capable of actually feeling emotion, he certainly seems driven by something more than mere programming, namely a desire for acceptance and a sense of plain curiosity.
In Westworld (and its sequel, Futureworld), the robots are ridiculously human precisely because they're supposed to entertain the human Guests. Some robots are even "sex models" for people who want to swing that way. Of course, A.I. Is a Crapshoot...
In Halloween III: Season of the Witch, most of the Mooks are actually this as is the version of Ellie that our hero escapes from the factory with, and which tries to kill him. Some believe she was actually a robot all along, including when she had sex with him.
The photonic library computer from the 2002 film adaptation of The Time Machine. The computer even gets visibly irritated at what he regards as stupid questions from the Time Traveler, when a real computer would simply and happily attempt to answer any of his inquiries regardless of what was asked. This means that for whatever reason creators gave him the same flaws as a human librarian would have, even though there was no reason for it and would actually hinder his performance as a library computer.
Creation Of The Humanoids combines this with an inversion of Transhuman Treachery to create a scenario where the despised robots, which are deliberately kept from becoming too human, conspire with a human scientist to create a new race of immortal human-replicating robots into which human personalities are downloaded at the time of the original human's death. The protagonist is the leader of the anti-robot movement, and it turns out that both he and the love interest he develops during the film have already been through the process.
In Wrongfully Accused, Leslie Nielsen's character sneaks into a hospital's computer room Mission: Impossible-style and discovers that the computer is, for some reason, Jewish (even the laser grid is in the shape of the Star of David, and it says "Shalom" when turned on). It immediately starts making Jewish jokes and then gets annoyed when the protagonist just wants him to print the records. It then fills the room with print-outs.