Theory 1: inside every transformer is the ability to shrink--but not enlarge--themselves and any of their components in robot or disguise mode (This would also explain why Sky Fire and Astro Train can fit groups of transformers who shouldn't fit inside them--and why Megatron and Sound Wave transform into things much smaller than their robot modes.).
Theory 2: Optimus stores his trailer in another dimension and can bring it to this dimension at will--either because any transformer can or because the matrix allows him.
Theory 3: like the Allspark in the first Michael Bay film, Transformers can fold themselves and different components over into very small objects; in Optimus's case, he would store the condensed trailer in his body.
Theory 4: like Mirage, Optimus's trailer can turn invisible and follows Optimus around everywhere while he's in robot mode.