Matthew Stovers ROTS novelization covers this.
The order was implanted during their training before even conscious awakening:
“Yes, sir.” A silent buzzing vibration came from a compartment concealed within his armor. Cody frowned. “Go on ahead, General. We’ll be right behind you.”
That concealed compartment held a secure comlink, which was frequency-locked to a channel reserved for the commander in chief.
Kenobi nodded and spoke to his mount, and the great beast overleapt the clone commander on its way down into the battle.
Cody withdrew the comlink from his armor and triggered it.
A holoscan appeared on the palm of his gauntlet: a hooded man.
“It is time,” the holoscan said. “Execute Order Sixty-Six.”
Cody responded as he had been trained since before he’d even awakened in his crèche-school. “It will be done, my lord.”
The holoscan vanished. Cody stuck the comlink back into its concealed recess and frowned down toward where Kenobi rode his dragonmount into selflessly heroic battle.
Cody was a clone. He would execute the order faithfully, without hesitation or regret. But he was also human enough to mutter glumly, “Would it have been too much to ask for the order to have come through before I gave him back the bloody lightsaber …?”
The mechanics of the implantation was revealed in Clone Wars cartoon - it was part of the Inhibitor Chip, installed - supposedly - to prevent clones from siding with rogue Jedi or Sith
You must remember the chip is a safeguard against betrayal from rogue Jedi. Master Sifo-Dyas was the only Jedi who knew of this. But with his passing, we alone know of this secret, and we must keep it that way. (src: Clone Wars, S06E02, "Conspiracy")
"That is a structural inhibitor chip, which is supposed to prevent you from being aggressive, like your source, Jango Fett. Jedi Master Sifo-Dyas instructed us to implant them during your growth cycle." (src: Clone Wars, S06E03, "Fugitive")
It was at the end, the end of the war. Our fellow soldiers, the clones, the ones we Jedi fought side by side with, were suddenly turned and betrayed us. I watched them kill my master. She fought beside them for years and they gunned her down in a second! Then came for me. Later they said they had chips in their heads that made them do it. So they had no choice. (src: "Star Wars: Rebels", S02E01, "The Lost Commanders")
And it seems that they don't actually think about details of why and what in terms of Jedi needing to be killed. Tup didn't (Clone Wars, S06E01, "The Unknown")"
- What happened?
- What do you mean?
- Do you have any idea what you've done?
Good soldiers follow orders.
Good soldiers follow orders.
...
- What is he talking about?
- I have no idea.
Good soldiers follow orders.
Good soldiers follow orders.
Kill the Jedi.
Ah! Ugh! Ugh! We have to get him back to the medical bay before he hurts anyone else.