Issue
This answer assumes that the integral belongs in the domain of $\varphi$, i.e.,
$$
\int_X\!f(x)\;dx \tag{1} \in {\rm dom}(\varphi)
$$
Even more, the statement we want to prove involves the evaluation of $\varphi$ at the value of the integral. So, a question remains: why does $(1)$ hold?
Let $a<b$ be the ends of the interval $I$ where $\varphi$ is defined (they may or may not belong to $I$). In order to show $(1)$ we need a hypothesis, namely
$$
\int_{\{f\notin I\}}dx = 0, \tag2
$$
i.e., $f\in I\rm\ a.e.$ (which does happen if $f(X)\subseteq{\rm dom}(\varphi)=I$)
Because of hypothesis $(2)$, to prove $(1)$ it is enough to show
$$
\int_{\{f \in I\}}f(x)\;dx \in I.
$$
Since
$$
1 = \int_X dx = \int_{\{f\in I\}}dx + \int_{\{f\notin I\}}dx
= \int_{\{f\in I\}}dx,
$$
we obtain
$$
a = \int_{\{f\in I\}} a\;dx \le \int_{\{f\in I\}}f(x)\;dx
$$
Now, assume $a\notin I$ and
$$
\int_{\{f\in I\}} f(x)\;dx = \int_Xf(x)\;dx = a.\tag3
$$
Then we would also have
$$
\int_{\{f \ge a\}}f(x)\;dx = \int_{\{f\in I\}}f(x)\;dx = a
= \int_{\{f\ge a\}}a\,dx.\tag4
$$
But $(4)$ means that $f = a,\rm\ a.e.$, which contradicts our hypothesis because $a\notin I$.
Thus $\int_X f(x)\,dx=a$ and $a\in I$ or $\int_X f(x)\,dx > a$. Similarly, $\int_X f(x)\,dx=b$ and $b\in I$ or $\int_X f(x)\,dx < b$.
In any case $(1)$ does hold and we can proceed as in the answer of reference.