The Captain has the authority to enforce dress and grooming standards on his/her aircraft. I don't know the full story here, but I'm willing to say the Captain may have been a bit too overzealous in this instance and probably could have been a bit more tactful to boot.