Well, I’m guessing on what you’ve used to connect it all up, but (to be on the safe side), I suggest cease and desist 🙂
Your problem is that you have a stereo device (CD) and a mono device (guitar) fighting to make their way out of another stereo device (your headphones). The fact that you can hear the guitar (pickups are an incredibly feeble source) surprises me, but there is the possibility I suppose to damage something (any amp in the way, the ‘phone speakers, your ears).
A mono jack (socket, and your instrument cable) has a source (or “hot”) tip and ground sleeve. A CD player’s ‘phones out has a “left” tip, a “right” ring and a ground sleeve. If you’ve used a stereo jack — 2 stereo jack splitter, then your ‘phones (tip, ring and sleeve) are in one end of the splitter and your CD ‘phones out (tip, ring and sleeve) is in one of the other ends. This should sound fine if left like that. As soon as you plug the guitar cable in, you’re throwing into the mix a mono tip and the ground sleeve is touching the splitter’s “right channel” ring receptor. Having grounded the right channel, you’ll hear that horrible “duuuur” noise you get if you press your thumb on the tip of a jacklead you’ve left plugged in the amp. You also won’t hear the right side of your CD, at the least.
A lot depends on what sort of splitter you’ve used. What’s male and what’s female? Is it stereo-stereo, stereo-mono?