The CD format of 16 bit 44.1 kHz is capable of high fidelity with huge dynamic range and full frequency response of 20 - 20 kHz. The equipment and tools used to capture the audio during recording, convert it to digital, mix, and master the end product are state of the art and often capable of resolution that far exceeds the capability of the human ear.
However, the engineers involved in the process are human and just as all doctors, lawyers, you-name-it-tradeperson is not created equal with the same exact knowledge and skills, neither are the engineers involved in the process. So some CDs are better than others.
No self-respecting engineer would purposely do a poor job of recording, mixing, or mastering the music. They do face pressures from the marketing type people that want the CD to be louder and stand out when played next to the competition - not unlike how TVs are cranked to 'torch mode' with the highest brightness and contrast settings so they appear to be more vivid than the others. If you really want to read about the disturbing trend of CD mastering, google 'cd loudness wars'.
Still, it is not fair to say that they don't produce 'the best sounding CD possible'. Some are phenomenally recorded, mix, and mastered and some are so compressed that there is practically zero dynamic range. Like everything else, quality varies. Of course a lot of people seem to be under the mistaken impression that the artists always do a perfect job of playing/singing the music and the engineers destroy it and that of course is ridiculous.