The muscles in the neck and shoulders run up to the head. When a person injures those muscles, they often feel it in their head, and that's why sometimes they'll get headaches. So, when you popped your head on the railing, you very likely wrenched your neck muscles too. That's why you feel pain in your neck, and is probably why the pain extends up to your head. Also, your head pain, you probably bruised the heck out of it, so it's going to be sore for a while.