The fact that a crab crawls out when it's being cooked doesn't mean that it's in its head saying "ah, it's hot, it's painful, I'm going to crawl out".
It only means that it has a stress response to an overheated environment. It's the same instantaneous reaction a person has when they touch a hot object. The whole process of touching, feeling, and then retracting is very fast, and in order to achieve that speed, the signal doesn't slow down to the brain for a turn, it only travels through the spine to cause the reaction action to occur.
At the same time, a small pain signal travels up the spine to tell the brain, "My hand is burning," before the brain responds, "Oh, I'm in pain. It's only pain up to here! When you see a crab struggling for its life, maybe it's just reacting to stress, and the thought of pain doesn't even cross its mind. Why would it need to know what pain is?