Solution
= Solution
<Bayes theorem> gives
$$
\log p(\theta\mid y)=\log L(\theta)+\log\pi(\theta)-\log Z.
$$
Taking its posterior expectation after subtracting $\log\pi(\theta)$ yields
$$
D_{\mathrm{KL}}(p(\theta\mid y)\Vert\pi)
=\mathbb E_{\theta\mid y}\log L(\theta)-\log Z.
$$
Thus the equality holds for every proper prior and valid likelihood for which the displayed expectations are well-defined.