To backdoor short messages or e.g. their prefixes, you can choose some deterministic public key encryption scheme $PK$ with short ciphertexts (not sure if there are ones suitable here), generate key pair $(Pub,Priv)$ and define hash as
$$H(m) = FirstBits_{128}(SHA256(m)) ~||~ Pub.Encrypt(FirstBits_t(m)).$$
$H$ will be "similar" to SHA256 in that first 128 bits would be the same. And, having the private key, you can make the preimage attack: given $(h~||~c) = H(m)$, you can recover $FirstBits_t(m) = Priv.decrypt(c)$. This recovers full short message or its prefix. In the latter case, you won't get a preimage for $H$ but only some information about the input.
Of course parameters can be adjusted, but the idea should work. I don't know whether such short public-key systems exist, but at least it could work for larger hashes.
Possible design for SHA512:
Disclaimer: I am not sure this is a good way to do public key encryption
We shall use curve25519 and a stream cipher (e.g. AES in counter mode or simply one-time pad). Let $G$ be the generator of the group. The hash designer generates private key $a \in \mathbb{Z}_{256}$ (there's some bit post-processing to be done, see the curve page) and computes public key $P=[a]G$ which has size 256 bits. Then, the hash function of a message $m$ is defined as:
- Compute a deterministic ephemeral key with, say,
$$b = SHAKE256(m).$$
- Compute the shared secret key
$$k = SHAKE128([b]P) = SHAKE128([ab]G).$$
- Compute the ciphertext
$$c = k \oplus FirstBits_{128}(m).$$
- Compute the digest
$$H(m) = FirstBits_{128}(SHA512(m)) ~||~ [b]G ~||~ c.$$
As a designer, you can utilize the backdoor in the following way:
- Let $$(h, [b]G, c) = H(m).$$
- Compute the shared secret key
$$k = SHAKE128([a][b]G) = SHAKE128([ab]G).$$
- Compute the ciphertext
$$FirstBits_{128}(m) = k \oplus c.$$
- Try to verify $H(m)$ by recomputing. This will fail either if $H(m)$ was modified (computed incorrectly) or if $m$ was longer than 128 bits.
Note that this scheme does not provide integrity for long messages. That is, even the designer can not distinguish $H(m)$ for long secret $m$ from random strings.