[proofplan]
We write the calibration assumption as an equality of conditional expectations with respect to the $\sigma$-algebra generated by the predicted probability $Z$. For a bin $I$, the event $A=\{Z\in I\}$ belongs to $\sigma(Z)$, so the defining property of conditional expectation gives equality of the integrals of $Y$ and $Z$ over $A$. Dividing by the positive probability of $A$ gives equality between the empirical event rate and the average predicted probability in that bin.
[/proofplan]
custom_env
admin
[step:Represent the bin as an event measurable with respect to the predicted probability]
Let $Z:=\hat p(X)$ denote the predicted-probability random variable. Let $\mathcal B([0,1])$ denote the Borel $\sigma$-algebra on $[0,1]$. Fix a Borel measurable interval $I\subset[0,1]$ with $\mathbb P(Z\in I)>0$. Define the event
\begin{align*}
A := \{\omega\in\Omega : Z(\omega)\in I\}.
\end{align*}
Since $Z:(\Omega,\mathcal F)\to([0,1],\mathcal B([0,1]))$ is measurable and $I\in\mathcal B([0,1])$, we have $A=Z^{-1}(I)\in\sigma(Z)$. Also, by hypothesis, $\mathbb P(A)>0$.
[/step]
custom_env
admin
[step:Use the defining property of conditional expectation on the bin event]The random variables $Y$ and $Z$ are integrable because $0\leq Y\leq 1$ and $0\leq Z\leq 1$ $\mathbb P$-a.s. Since $A\in\sigma(Z)$, the defining property of $\mathbb E[Y\mid\sigma(Z)]$ gives
\begin{align*}
\int_A Y\,d\mathbb P(\omega)
=
\int_A \mathbb E[Y\mid\sigma(Z)]\,d\mathbb P(\omega).
\end{align*}
Using the calibration assumption $\mathbb E[Y\mid\sigma(Z)]=Z$ $\mathbb P$-a.s., we obtain
\begin{align*}
\int_A Y\,d\mathbb P(\omega)
=
\int_A Z\,d\mathbb P(\omega).
\end{align*}[/step]
custom_env
admin
[guided]The purpose of introducing $A$ is that it describes exactly the observations whose predicted probabilities fall inside the interval $I$. Because $A=Z^{-1}(I)$ and $I$ is Borel measurable, the event $A$ is measurable with respect to $\sigma(Z)$. This is the key measurability point: conditional expectation with respect to $\sigma(Z)$ controls integrals over every event whose occurrence is determined by $Z$.
The random variables being integrated are integrable. Indeed, $Y$ takes values in $\{0,1\}$, so $0\leq Y\leq 1$, and $Z$ takes values in $[0,1]$, so $0\leq Z\leq 1$. Therefore
\begin{align*}
\int_\Omega |Y|\,d\mathbb P(\omega) \leq 1,
\qquad
\int_\Omega |Z|\,d\mathbb P(\omega) \leq 1.
\end{align*}
Since $A\in\sigma(Z)$, the defining property of the conditional expectation $\mathbb E[Y\mid\sigma(Z)]$ yields
\begin{align*}
\int_A Y\,d\mathbb P(\omega)
=
\int_A \mathbb E[Y\mid\sigma(Z)]\,d\mathbb P(\omega).
\end{align*}
The calibration hypothesis states that $\mathbb E[Y\mid\sigma(Z)]$ equals $Z$ almost surely. Replacing the conditional expectation by $Z$ inside the integral is valid because changing an integrable random variable on a $\mathbb P$-null set does not change its integral. Hence
\begin{align*}
\int_A Y\,d\mathbb P(\omega)
=
\int_A Z\,d\mathbb P(\omega).
\end{align*}[/guided]
custom_env
admin
[step:Divide by the bin probability to obtain the conditional expectation identity]
Because $\mathbb P(A)>0$, the conditional expectations given the event $A$ are
\begin{align*}
\mathbb E[Y\mid A]
&=
\frac{1}{\mathbb P(A)}\int_A Y\,d\mathbb P(\omega),\\
\mathbb E[Z\mid A]
&=
\frac{1}{\mathbb P(A)}\int_A Z\,d\mathbb P(\omega).
\end{align*}
The integral equality from the previous step therefore implies
\begin{align*}
\mathbb E[Y\mid A]
=
\mathbb E[Z\mid A].
\end{align*}
Since $A=\{Z\in I\}$, this is exactly
\begin{align*}
\mathbb E[Y\mid Z\in I]
=
\mathbb E[Z\mid Z\in I].
\end{align*}
Finally, substituting $Z=\hat p(X)$ gives
\begin{align*}
\mathbb E[Y\mid \hat p(X)\in I]
=
\mathbb E[\hat p(X)\mid \hat p(X)\in I],
\end{align*}
which proves the claim.
[/step]