Role of transformation

In addition to making the toys cooler than anything else, ever, transformation plays a role in the fiction. This is not as straightforward as it sounds. Since people relate best to humanoid figures, and since a Transformer in robot mode can usually do anything necessary for the story, the creators need to provide reasons for them to transform to their altmodes. Here is a sampling of those reasons.

Disguise
The original reason was that they were "robots in disguise". In Generation 1, upon arriving on Earth, the Transformers took on Earthen altmodes so as to move unobserved among human society. This is also the primary reason for Transformation in the current IDW continuity. In most continuities, these disguises fool both "the locals" and other Transformers, though there are exceptions.

While usually the disguise justification only applies to A) Transformers with mechanical altmodes, who B) take on Earth-based forms, there are variations. In Spotlight: Ultra Magnus, the titular hero takes on the form of a Nebulan truck so as to remain disguised on that world. In some continuities, the Pretenders can use their shells to disguise themselves as normal organic beings. (In other cases, they're just disguised as "not robots".) And, in a few instances, Transformers from the Beast Era use their ability to mimic normal animals to hide undetected.

Transport
In those stories set before the Transformers come to Earth, altmodes are usually not disguises. The primary justification for them is that they are better suited for getting from point A to point B quickly. In a few cases they have abilities that can not be accessed in robot mode, such as flight, construction capability (e.g., a crane), or better hauling capacity.

Protection from energon
In the first season of Beast Wars, the Earth's vast energon deposits were actively harmful to Transformers in robot mode. The flesh of their adopted beast modes, however, could protect them from the radiation. They thus used their robot modes outside their respective bases only when necessary.

Stealth
During the conflict chronicled in Beast Machines, the Maximals' technorganic bodies were invisible to Vehicon sensors, but only in beast mode. The Maximals would therefore fight in robot mode, but transform back to beast mode when they needed to sneak around.