There are many reasons for this everyday (yet absurdly nauseating) phenomenon. Typically, though, it is simply due to a loose wire and can often be set by pushing the cable in the direction of the earpiece and, if needs be, affixing it into place with a little electrical tape, super glue, or other glue.
Now and again, if ever the earpieces have an inline volume wheel, that may be the cause. That one is slightly trickier to mend, but you could always try the ‘wire trick’ described above and see if it works. If not, then open the volume controls and re-solder the wires into place (be warned, this may invalidate most warranties, so if the ‘phones remain covered, just send ‘em back and get replacements).
Avoiding stuff like this happening in the future, it’s recommended to wrap your cables carefully and to avoid stressing your headphones. No, I do not mean that you should give Motorhead a rest and only play floaty, soothing New-Agey music on them, I mean that you should not have them in your back pocket when you sit down and it is best to remove them carefully from your ears after use (this will sound obvious, but you’d be astounded how many individuals just rip ‘em out).
Another thing to take care for is the jack, if ever the cable is fraying/wearing round the jack, then that will also be a problem. Luckily, like so many everything in life, a bit of electrical tape can really come in useful, just be sure that all the copper wiring is tightly bound and it should go back to standard usage in no time.
Now and then, however, it is simply an indication that the headphones are knackered and no quantity of skillful tinkering can mend them. Typically, in these cases, the challenge is inside. This particular variant on the trouble also catches headphones of any price range, be they Poundland specials or your year old Sennheiser Eargasm headset. I’m reminded of the Shakespeare quote from Hamlet, something about a king and the guts of a beggar, but I can not be bothered to look the entire thing up right now. You get the purpose I’m trying to make though, everything dies eventually, no matter just how much it cost you.