Unfortunately, in many comics and cartoons of the 80's and in the case of the Hulk (and Ant-man, Giant Man, Yellow-jacket, Hank Pym, also of Marvel fame) even longer, the relationships between size and mass has always been a bit hand-wavy. Characters are often seen changing size, growing incredibly large (or small) without ever asking (or explaining) where all of that mass is being stored between transformations.
Megatron and Soundwave were two of the most noticeable users of "mass displacement" from the first generation Transformers. Megatron became a handheld weapon that was able to be used by humans, Soundwave would become a cassette that could be played in a standard human tape deck, without adding any of his supposedly considerable mass adding any weight to the device.
So you are forced to assume one of two things:
- When they changed size, they moved their mass (in an unexplained fashion) outside of the current universe or transformed it into a mass-less form (perhaps dark matter) while retaining all of their functionality and intelligence
- They compressed their atomic structures but were somehow able to render that mass inertial-less, so it would appear to any human interacting with them as if they had no more mass than would be expected from a device of that size.
This does not explain those Transformers who grew considerably larger in their transformed state or the mysterious disappearance and reappearance of Optimus Prime's cab section during his transformation from truck to robot...
In the 2003 short run comic release of Transformers: More than Meets the Eye, an attempt was made to explain the "mass displacement" technology as one of the many technological advancements of the Cybertronians. They created a substance called Ore-13 that was partially responsible for the transformation. Little other explanation was given and Ore-13 was presumed to be relatively rare, so few of the Autobots/Decepticons possessed the ability.