Pain after swallow. Pill stuck in the esophagus triggering spasm of esophagus. No sensory nerve inside body to tell precisely which organ is hurt but functional symptoms reveals the culprit. Usually saliva will be secreted enough to melt the pill so it can travel gradually downward (in case you do not have water within reach of course).
Esophagitis. If your chest hurts while taking a pill it is most probably due to pill esophagitis. It depends on the size of the pill and the medication. Check with your doctor whether you can take a liquid form of the same pill or a smaller tablet. A regular dose of Prilosec may also help.