Recently a relative's son fell and his doctor was concerned pain in his testicles could be causing his problem walking, he checked them to make sure there was no swelling, lumps or bruising causing pain when he walked to rule out testicular tortion, which can cause loss of a testicle and is a surgical emergency.
http://www.emedicinehealth.com/testicular_pain/page2_em.htm
Since the doctor asked you to remove your son's underwear and checked him with you there I doubt there was anything of a weird nature going on, I'd say it was a necessary exam right along with checking his gait, joints, muscles, etc. Also, not knowing how old your son is I'm thinking the doctor may have felt he wasn't able to explain exactly where the pain causing him to limp was (my guy is 3 and he might have a problem pinpointing it) and the doctor simply wanted to make sure there wasn't anything of a serious nature needing immediate and intervening attention going on.
I've known doctors who aren't good at explaining what and why they're doing something, just not great communicators and kind of in their own world, and if they do something I wonder about or question I speak up immediately, "And what are you checking for by doing this?"
BTW, my guy's pediatrician had me take his underwear down at his checkup earlier this month so she could check things out, she always does. I've read doctors should do this at yearly checkups and I'm glad she does.
Hope your son is doing good and no longer limping or hurting : )