In one line: when you black out part of a lossy-compressed image, information can survive outside the box. JPEG has a locality guarantee ("leave an 8px margin — 16px with chroma subsampling — and nothing leaks past the box"); lossy WebP (VP8) does not. So redact the uncompressed original and export losslessly.
The typical flow looks like this:
It is tempting to think "I saved it as PNG, nothing degraded, and what was under the box is gone". The problem is step 1. A lossy encoder looks at the whole image to decide how to spend a limited number of bits, so the secret pixels influenced how error was distributed in the pixels outside the box. If an attacker can enumerate candidates (YES or NO, a four-digit number, ...), replay the same pipeline, and pick the candidate whose artifacts outside the box match best, they can infer what was hidden.
This is not an X-ray that peels off redactions. As kornel notes, it only works when the attacker can reproduce the original quite precisely (fonts, layout, background) and can enumerate candidates. Screenshots, though, tend to meet exactly those conditions, since you can re-render the same text with the same OS and fonts. It is the same structure that let tools like Depix defeat pixelation and blur by rendering candidates and comparing them.
Baseline JPEG cuts the image into 8×8 blocks and applies a DCT and quantization to each block independently. The quantization table is fixed for the whole image (set by the quality setting), so the quantization error of a block depends only on that block's pixels. DC coefficients are coded as differences from the previous block, but that happens in the lossless entropy-coding stage and does not affect reconstructed pixels.
So the reconstruction of a block that contains none of the secret pixels does not depend on the secret. If you extend the black box to cover every block that might contain secret pixels (in practice, "an 8px margin"), nothing remains outside it.
There is a catch. With chroma subsampling (4:2:0), the chroma planes are halved in both directions before being split into 8×8 blocks, so one chroma block covers 16×16 pixels of the original. On top of that, the decoder's interpolating upsampler mixes neighbouring samples. So for a 4:2:0 JPEG, 8px is sometimes not enough.
Lossy WebP is VP8 video key-frame (intra-frame) coding. Unlike JPEG, it has: