In primitive society, men won women's hearts by dancing. The better you dance, the more you can keep up with the rhythm, and often you get the right to mate. So that his genes can be passed on. So after tens of thousands of years of evolution, dancing to music has become an instinctive impulse.
But after entering the present society, dance has lost its original meaning. Nowadays, women don't marry a man just because he dances well (of course, there are some cases), so this instinct gradually degenerates. So now we have the urge to dance when we hear music, but we won't dance unless we don't care at all.
By the way, instinct can be regarded as subconscious, so dancing while listening to music is really influenced by subconscious.