Definitely, with the caveat that the duty of a pilot is to protect the cockpit at all costs. If someone uses a shoelace to take a flight attendant hostage and threatens to kill her, the pilot should not leave the cockpit to intervene. Using the plane to hit the hijacker with some nasty g-forces is probably a good idea, but the pilot must not do anything that might risk cockpit security.
Note that I would not expect an armed pilot to act as a sky marshal; the two jobs are very different, and for a pilot to carry his gun into a cabin would be an invitation to disaster. Even within his limited role, however, (keeping control of his 100-ton missle), a pilot may in some cases have need of a sidearm and should thus be allowed to have one.