'Head over heels' can also mean 'to fall over'.
The man slipped on the ice and fell head over heels. (The man slipped on the ice and fell over.)
So it's fairly easy to see how it can be used to describe falling in love e.g. They fell heads over heels in love. (They fell deeply in love with each other).
The first sentence, I don't think it's an expression as such. Having read the lyrics of the song (I have to admit it's not my kind of music so I had to google it) I think the writers of the song have subverted the meaning of the well-known expression, and changed the meaning to the opposite.
Now I'm heels over head
I'm hangin' upside down
Thinking how you left me for dead
This is someone who is upset about the relationship finishing, someone who is in turmoil about it. Sometimes you can describe that as feeling upside down or mixed-up, which is why I think they have changed the order of the words, as a literary device to show this. It's not really an idiom, I mean I had to do a bit of searching to arrive at this conclusion.
'Heads over heels' is the idiom.