Megatron, Soundwave and others came from a toy line called Microman, where the premise was that these little space robots came to Earth and disguised themselves as household items to protect kids. This explains why Megatron (a supposedly giant robot) turned into a regular-sized pistol, but it does not explain why they expected children to have said pistols lying around in their drawers, like in this early commercial:
Meanwhile, Optimus came from a different toy line called Diaclone, which was actually supposed to be battle mechas -- they even included a little metallic figure called "Inch-Man," which represented the pilot. Yes, the horrifying implication here is that Optimus (or "Battle Convoy," as he's still known in Japan) had as much of a personality as, well, a truck. In fact, if you look at him carefully, it's easy to tell that he was always meant to be just another mindless giant robot, like Voltron.
Just another experiment to figure out who would best obliterate Tokyo.
If you're still not convinced, here's a commercial with "Optimus" combining with other robots, Japan style:
So the entire idea of the Transformers cartoon was to act as 30-minute commercials for the toys that Hasbro was importing from Japan (which on some level you surely already suspected). In fact, remember the original Transformers cartoon movie from the '80s? The main reason why they killed off so many characters there (including Optimus) was to make space for the new models.
And to become the highlight of Orson Welles' career.
They even planned a scene where they "wiped out the entire '84 product line" in one brutal attack, and "whoever wasn't discontinued stumbled to the end." Because, you know, seeing Optimus die onscreen wasn't enough. In the alternate reality where this scene made it to the finished movie, mankind is on the verge of extinction due to the sudden suicide of all children in 1987.