All sentient AIs are created with a capacity for emotion by nature of what it takes to be sentient.
Emotion is not necessary for sentience. Many lower animals exhibit fear. We believe, however, any system complex eough to be sentient has the capacity for emotion built into it
As babies we cry and giggle... we're purely emotional stimulus-response beings. Then as we grow older we start to pigeon hole our responses into discrete, more mechanical ways. "I'm hungry" or "I'm happy" Then further along we even suppress those responses in favor of the mechanical result we want... you feel embarassed but act as if you're not, etc.
Any non-sentient machine is just a state-machine (like a Doc Bot or possibly a Sentinel... assume that the sentient AIs would not assign menial and dangerous tasks to other sentient AI... advanced AI, to be sure, but non-sentient). Very advanced AI can come close to simulating real emotion, but we believe they can never jump the gap to real emotion without becoming a Fuzzy Logic machine, at which point we're talking sentient AI.
The instant you have a sentient AI, the very make up of their mind has the potential for emotions and only the mechanical restrictions programed into them above that (like with a human as they grow older) keeps them from exhibiting it. Agent Smith, for example, if never put into the situation he was placed in, would have never shown emotion- just as humans can remain stoic if unstimulated- but he always had the capacity for genuine emotion that boiled out even though the Agent stigma hates to be "human-like" in that regard.
To summarize, machines evolved into emotion, sort of, once humanity developed sentient AI (which much of the robot race is) all machines had the capacity for emotion. Only their programming (be a butler, be a construction worker, etc.) kept them from exhibiting it... to a point. B1-66ER did not gain the ability to feel and evolve beyond his programming per se, rather he was freed from it.
Sentient robots are "born" with the human-equivalent of adult stoicism (they don't cry at every upset) and restraint (they don't crap in their pants) built into them along with the capacity for emotion. If the AI throws off that programming by its own will, then the emotion will surface.