In a world full of fusion cannon, ion blasters, and laser rifles, when the chips are down, the best thing a huge transforming robot can rely on in a fight for the future of the universe is a sharpened hunk of metal.
Swords are ubiquitous in the world of Transformers. Many bots have one or more of these in varying arrangements. Knives show up every so often too, and one guy was once issued an energy weapon with a bayonet.
Swords range from Grimlock's energon sword, to Vector Prime's weapon that can slash reality, to the blades that Starscream had during the Unicron trilogy, to the dinky little dagger that Armada Megatron and Cybertron Hot Shot carried at the same time.
Note that the aforementioned Megatron and Hot Shot carried enough firepower to level some of the smaller states of the Union.
In a real-world sense, swords are often seen as one of the cooler melee weapons, and humans have used them in their own wars quite often, relenting only when guns and so on started getting a little more reliable. And they still issue knives anyway, sometimes sticking them on the guns.
Mecha series (and let's face it, the only thing missing from Transformers to make it a traditional mecha show is the fact that they don't really need a pilot) focus on the cool giant robot interaction. And when that interaction involves combat, why not grab a sword? A clash of blades is almost iconic in fighting imagery--and if you say there's no place for that in science fiction, there's a film series you should see called Star Wars...