The reason for this is basically that most codecs do not target SSIM internally. They're using their own algorithms to determine how to allocate bits, so two images with the same SSIM may look better or worse depending on what codec is used. Many modern codecs (e.g. from x264 onwards) deliberately take approaches that lower the score of the result on objective metrics but usually look better to the human eye.
This exact issue was originally highlighted on the x264dev blog: "How to cheat on video encoder comparisons" #3: "Making invalid comparisons using objective metrics". [1]
If you really want to compare image codecs, I'd look at one of the many comparisons from this family on Github. [2]
In my judgment WebP is clearly better than Mozjpeg for most images.
[1] https://web.archive.org/web/20141103202912/https://x264dev.m...
[2] https://wyohknott.github.io/image-formats-comparison/#abando...