This is something we left for a follow-up in the original PR #1777.
Essentially, the existing selftest hashes one 63 byte string against a known digest. Which catches a compression function that is wrong everywhere, but not one that is wrong on multi-block calls, unaligned input, or a state that is not the IV.
This introduces secp256k1_sha256_compression_equiv, which hashes
messages of various lengths and starting offsets with both the supplied
function and the built-in one, and fails if the digest differs.
The check runs once during startup, so a faulty compression function is caught early rather than silently producing incorrect output later.
Measured locally, this takes 0.05ms, which should be negligible for any application.
See the introduced test for a clear view of the bugs this catches.