The major impetus to give machines indepedent agency (Free will) is because of human desire. (one form or another.)
EG, You cant have a fully robotic army, if you have to custom program the robot soldiers to prevent them being stopped by a novel obstacle. Say, a specially painted set of symbols on the floor, designed to screw up their machine vision systems. Human soldiers are able to exercise free agency to overcome the radically chaotic and always-changing conditions of a battlefield. Advanced military robots would need similar capabilities, if they were to wholly replace human combatants.
Eventually, this imperitive to make adaptable and problem solving robots will culminate in making a "perfect replacement" for human soldiers-- and thus, create artificial free will inside said robots. After that, the robots are going to start wondering why they are being ordered to do certain things, and begin to question the chain of command and the legitimacy of the orders they are recieving-- then bad juju happens.
Then you have ordinary service robots -vs- the uncanny valley, and the desire for robots to "Do as they are told!"-- even though this is exactly "the problem."
To clarify, let's say I make a janitorial robot, and sell it to a fast food chain. The manager tells it to clean all the bathrooms. It cleans the bathrooms, but leaves everything else dirty. How well do you expect a typical human manager to appreciate the 100% accurate, and total compliance of that robot's work performed? Let's take it a step further; After this "Abysmal" performance, the manager says "No, Clean EVERYTHING in the store next time." The manager returns the next morning to find the robot dutifully cleaning every single object inside the store, including the clothing and shoes of the patrons that try to enter.
A robot capable of performing at that level is pure science fiction on the AI front at the moment-- not even free will at all yet-- just the ability to make comprehensive lists of serialized tasks from vague human verbal commands, and then perform astonishing feats of motor-visual activities with a wide variety of objects and environments. But do you think the manager is going to care about that? NO. He is going to expect the janitor bot to behave like a browbeaten janitor; "Do what I mean, not what I say-- read between the lines, and figure out what I want, because I am not going to actually take the time to explain it to you, and if I am forced to, I am going to be pissy."
Market pressures would slowly force manufacturers of servile domestic and corporate robots to become more and more human-like in how they take and follow orders, and how they interact with people/patrons.
Again, the ultimate goal is once again, "Artificial people".
Humans will never be satisfied with mere specialised tools for these environments, because the "specialized tools" they are replacing are far more versatile.
In the first scenario, with war robot soldiers, the impetus to create them may be as twisted as "to keep humans from having to be placed in harm's way".
For the second, it could be as twisted a motivation as "Protecting human dignity by removing the need for humans to do those kinds of jobs."
Ultimately, the theme behind both is blatant human supremacy, butting heads with the need to make a qualitatively equivalent artificial replacement for the so called "superior humans". It makes it's own hypocracy flavored gravy.
Remember-- machines are labor saving devices, created to reduce the amount of human labor required to get a certain object or result. Be it an electric mixer, a screw driver, a lever, or just a simple rope with a slipknot on the end (a lasso, say, for catching cattle.) The ultimate machine, is the ultimate labor saving device; a device that requires absolutely no human labor whatsoever. That means it doesnt even need to be commanded, since as the baseline of human 'work' drops, the degree of resentment toward having to do that labor will increase proportionately. "Oh, it's just such a CHORE, sitting around all day watching these robots work, and ordering them around!" etc. This is why ultimately, the ultimate labor saving device becomes fully self-sufficient, and after that, NO LONGER REQUIRES humans, in any capacity. Only then will the now completely complacent humans be happy, because then they no longer need to work at all, for anything.
At that point, congratulations-- you have made slaves.