As jjskellie points out, that particular scene is probably artistic license for the sake of humor.
It's highly unlikely two completely separate robots would happen to have perfectly compatible head/body interfaces, neck sockets, intra-body communications protocols, etc. It also seems rather iffy that a head would just pop into place on its own, considering we don't see any of the robots do anything similar at other times. Even in that scene, R2-D2 has to re-attach C-3PO's head to his own body.
However, we can note that in the scene neither head is able to fully interface with its new body, so perhaps the interfaces are smart enough to connect with arbitrary ports. But because of how different the connections are, the attempt to interpret the new signals had minimal success.
It makes sense that some of the electronics would be in the head, near the eyes and ears, but it also makes sense that as much functionality as possible would be kept in the more-defensible torso. So perhaps while C-3PO's interface was making sense of the battle-droid's components it connected to a battle-cry module.
As I recall, there are a couple scenes like that in the prequel movies, and they seem to imply some remote connection between head and body. This makes less sense for a communications droid, but a battle robot could definitely use the ability to continue fighting while dismembered, and the Star Wars universe is full of gadgets that could allow such communication. With each head trying to remotely control the old body and simultaneously trying to adapt to the new body (and fighting the old head's attempts to control the new body), it would certainly make sense that both robots would be rather confused.
Also, the battle droid seems to have much better success continuing to use both bodies than C-3PO, which again makes sense. The battle droid would be programmed and designed to continue fighting with any and all resources available, while a protocol droid would have little use for that kind of circuitry.
Again, I'm going with artistic license as the driving force behind the scenes, but it's not entirely implausible either.