In short, very roughly, they don't compress pixel values directly, they apply a special transformation (wavelet transform) and then compress the coefficients from that transformation.
As to more detailed explanation, I haven't worked with image compression algorithms at this level.
However, very roughly, in craw, they compress RGB channels separately. For each channel, they apply so called wavelet transform, which produces discrete (integer) coefficients for each pixel. Those coefficients can be encoded/compressed more efficiently than the original pixel values, without losses (yet). Which means, one can recover the original pixel values from those coefficients.
Then they apply some lossy procedure on those coefficients to prepare them for better encoding. And then they do lossless encoding of the lossy coefficients.
To complicate things, they apply transformations on different subbands of the image as on that figure from
https://github.com/lclevy/canon_cr3#c-raw-lossy, but I'm not sure how it all gets combined.