The problem is too much vibrations. With the trunk lid open, you are releasing most of the sound pressure from inside the vehicle, decreasing the SPL inside the cabin, causing less vibration. With the trunk closed, you are simply too loud and vibrating the hell out of the CD player, causing it to skip.
Simply solution is to not turn it up as loud, or buy a new CD player that has better shock absorption abilities.