Shame (and also guilt) is the emotional equivalent to what we call "pain" in the realm of physical sensations. It's a very important signal to let you know that something is wrong and you need to take action to fix it before it causes further harm to you.