My kids always calmed down instantly when I give them medicine. It's like magic! I think it's the taste and the sweetness. They use glucose (and used to use honey) to soothe babies during procedures (like circumcision). It actually has a pain-relieving effect on babies.
The other thing that may be happening is the "magic juice" effect. When a kid is hysterical, you give them some juice to drink, and they're suddenly rather calm, and stay that way. It's because they HAVE to calm down to drink, or they'd choke on it. It really has nothing to do with the juice, just the act of drinking. This may be happening with the medicine.
My kids always did really well with Baby Orajel, too. It works very quickly to ease the pain. I tried it out, and it's quite awful stuff. My BIL tried it and said there was no way he was going to put that in his kids' mouth! But he didn't have a toothache. So all he experienced was a nasty (to us) taste and an odd tingling sensation. I, on the other hand, was having wisdom tooth pain, and wow, it WORKS! It was wonderful. After that tast and tingling sensation, there was nothing. No pain, no tingling, no taste.