One of the reasons I really like movieverse Optimus Prime is that his behaviour seems refreshingly alien to me now, that his own codes of ethics and morality have gradually progressed during the course of the three movies from something that the average human would consider proper and justifiable to something that seems much more objective, pragmatic, and, well, machine-driven in nature. And I do mean ‘progress’. A somewhat alien-thinking, impossible to fully predict Optimus is much more interesting to me than an Optimus who’s really just a big guy in a metal suit standing in for a standard human hero.
Here’s one possible interpretation of how his thought processes might have changed if he really has gone ‘alien’... First, I do think Optimus started off as somewhat human-standard insofar as what constitutes the average person’s definitions of ‘goodness’ and ‘heroism’. Had he been able to defeat Megatron in the first movie, I believe Optimus might have let a wounded Megatron slink off with his surviving minions. He would have read him the Autobot version of the riot act—“Show your face on Earth again and I’ll ensure that you no longer HAVE a face.”—but he would have let him live. That would have been the noble thing to do, the human thing, to show mercy even to your enemy. Not the smartest thing to do, but that’s part of being a human hero too, to be a little stupid sometimes for the sake of upholding your morals. As it was, Megatron kicked his butt and Optimus prepared to sacrifice himself instead. Again, a noble choice. Luckily averted, but still…I think most people would consider his intent there heroic in nature…
By the time ROTF rolled around, I think something must have happened that began inherently altering Optimus’s response to the Deception threat. Perhaps the body count, the amount of destruction wrought during the unfilmed months built up bit by bit just as rain caught by a tipping bucket rain gauge builds up drop by drop until the collection unit clicks over to start anew. Except that in Optimus’s case, his ‘clicks’ didn’t record units of rainfall, they amounted to an ever increasing escalation of potential aggression. Eventually, his aggression shifted from merely reactive to proactive. The loss of the AllSpark may have played a role here too. Perhaps its loss even WAS the factor that began the escalation or forced the shift—with all hope of creating more Transformers gone, I’d say it would be very logical for Optimus to become much more protective of those few Autobots that are left and begin expanding that umbrella of protection over his new alien comrades as well. In short, he no longer wants to just chase away the predators threatening his flock, he now wants to destroy them completely. By hunting, traps or poison, the ethics of how he does it isn’t so important anymore, Optimus just wants them all GONE.
Acquiring Jetfire’s sacrificial parts and a greater degree of power probably cranks Optimus’s innate potential aggressiveness even higher. And sometime during the intervening years and by the time DOTM starts, his protective drive expands yet again to encompass the entire Earth. Optimus has now become utterly naturalized. He now feels it his sworn duty to protect his new home and all its inhabitants, even if said threats should come from his former home or even former colleagues. If it’s Deception in nature or in league with the Decepticons, it’s become something to be eradicated. Exterminated. The betrayal of Sentinel Prime, that just triggers the very last click. Never again will Optimus Prime allow any second chances, be agreeable to parlaying with enemies or playing at posturing. Threaten his adopted planet and people in the least again, and he’ll retaliate in full immediately. And so he should. Cause that’s the way I like my Optimus!
Given all that, it should now be easy to understand how such an Optimus Prime could still say that “Freedom is the right of all sentient beings.” and sincerely believe it. Because from his mindset and his viewpoint, the very act or even intent of causing harm to any of HIS charges instantly negates your right to consider yourself sentient. Malicious destruction and preying on others, that's what animals do, Optimus might think…sick, instinct-driven, non-thinking animals. The kind of living organisms Optimus no longer has any qualms about putting down.
Or something like that. It’s entirely possible that the movies just had crappy, inconsistent script-writing.