If you are heavily injured and in a lot of pain while having something that can stop your suffering immediately, then self-preservation may be the last thing you'd be concerned about. Your brain wants to stop the immense pain in the first place, and if you realize that death stops it, then suicide may be automatically deemed a good remedy. Discomfort avoidance doesn't care about survival, it motivates you to resolve discomfort by any possible means. It's only a matter of circumstances whether prevention of discomfort also prevents potentially lethal self-harm or does the exactly opposite thing.