Oh boy, I'm a bit late to this one but this IS an interesting thread.
I've said this before and I'm not going to reiterate my essay on Transformer reproductive methods in full again to spare everybody's sanity, but to cut a long story short,
one method Transformers would reproduce would be, well, the old-fashioned way, with the exception that instead of producing a full baby, instead they produce a spark which must then be implanted into a constructed body, and also would possess some "passed on" knowledge rather than being completely childlike. Boom, there's your reason for TF sexual dimorphism.
If you want to develop things a bit further, of course, that's possible too. Whilst reproduction requires a male and female, the actual
functional process is entirely spark-based and thus the, uh, "interface" doesn't have to be standardized (helpful for Transformers with unusual body types/chassis configurations). The actual physical side of it could be as chaste as a kiss or some kind of hand-holding process, but could also be more, ahem, conventional or possibly much...kinkier. In addition, depending on the particular subculture (different colonies having different standards) the protocol regarding the whole affair varies massively; some might view it as a sacred act to be performed in ceremony, others might consider it a purely functional affair with no frills or niceties, but for the most part it's probably viewed much the same way as here- it's something enjoyable but to be done in private.
As far as dimorphism/gender roles go, as standard males and females look different to each other in much the way you'd expect. Gender roles are fairly non-existent as, being mechanical, strengths and weaknesses are generally determined by character and basic engineering rather than biology. Of course, being mechanical beings that can rebuild and alter their bodies as needed, technically speaking they can look like whatever they want (so a "male" Transformer might rebuild their body to appear totally female and refer to themselves as female because they feel like it, and if they get bored of it they might swap back or go for something "in between"). However, because reproduction is a spark based process, then there MUST be a male and female spark to reproduce- the body is irrelevant and no amount of retrofitting will change that. Of course, same-spark-sex relationships (and, uh, other stuff) do exist, but they can't reproduce.
...Well, that ended up being longer than I expected.
But TLDR: Genders exist for similar reasons to on Earth, with the caveat that external gender (but NOT reproductive gender) is entirely cosmetic and can be tweaked more or less as desired.