Why did Optimus Prime tell Sam Witwicky to push the cube into Primes chest instead of just attacking Megatron with it?
I seem to remember it was somewhere stated that Megatron was (a lot?) stronger/more powerful than Optimus. So Optimus probably deemed it too risky to get the cube anywhere near Megatron where he might actually get hold of it. Optimus basically expected to lose the fight, and if he had to die anyway he might as well destroy the cube to keep Megatron from getting hold of it, and thus save the world.
Why did Sam choose to ignore his command? Sam had no idea what it would do if it entered Megatrons body, for all he knew it could have made him uber as.
Assuming I remember correctly that Optimus was weaker than Megatron, Optimus would've used the cube straightaway if it really yielded super powers. Since he didn't, Sam probably anticipated Optimus to die a heroic death in the attempt to destroy the cube. Sam assumed that Megatron wouldn't expect him to actually attack using the cube, and therefore used the element of surprise, thus causing the destruction of both Megatron and the cube.