[guided]The key point is that an $\mathcal I$-measurable random variable can only depend on invariant information. Under ergodicity, invariant information is probabilistically trivial.
For each $a\in\mathbb R$, define the event
\begin{align*}
A_a:=\{\omega\in\Omega:Y(\omega)\le a\}.
\end{align*}
Because $Y$ is $\mathcal I$-measurable, $A_a\in\mathcal I$. Since the process is ergodic, every event in $\mathcal I$ has probability either $0$ or $1$, so
\begin{align*}
\mathbb P(A_a)\in\{0,1\}.
\end{align*}
We now prove that this forces $Y$ to be almost surely constant. Let $\mathbb Q\subset\mathbb R$ denote the set of rational numbers, and define
\begin{align*}
c:=\inf\{q\in\mathbb Q:\mathbb P(Y\le q)=1\}.
\end{align*}
The rational numbers are used so that the later unions and intersections are countable. We must justify that this infimum is finite. Because $Y:\Omega\to\mathbb R$ is finite $\mathbb P$-a.s., the events $\{Y\le m\}$ for $m\in\mathbb N$ increase to an event of probability $1$. Continuity from below for the probability measure $\mathbb P$ gives
\begin{align*}
\lim_{m\to\infty}\mathbb P(Y\le m)=1.
\end{align*}
For every $m\in\mathbb N$, the threshold event $\{Y\le m\}$ lies in $\mathcal I$, so ergodicity gives $\mathbb P(Y\le m)\in\{0,1\}$. A sequence taking only the values $0$ and $1$ and converging to $1$ must equal $1$ for at least one index; hence there exists $m_0\in\mathbb N$ such that $\mathbb P(Y\le m_0)=1$. Thus the defining set is nonempty.
We also need to know that the defining set is not all of $\mathbb Q$. Since $Y$ is real-valued $\mathbb P$-a.s., the events $\{Y\le -m\}$ for $m\in\mathbb N$ decrease to an event of probability $0$. Continuity from above for $\mathbb P$ gives
\begin{align*}
\lim_{m\to\infty}\mathbb P(Y\le -m)=0.
\end{align*}
Each probability $\mathbb P(Y\le -m)$ is again either $0$ or $1$, so there exists $m_1\in\mathbb N$ such that $\mathbb P(Y\le -m_1)=0$. Therefore $-m_1$ does not belong to the defining set, and $c\in\mathbb R$.
If $q\in\mathbb Q$ and $q>c$, then by the definition of infimum there exists $r\in\mathbb Q$ such that $c<r<q$ and $\mathbb P(Y\le r)=1$. Since $\{Y\le r\}\subseteq\{Y\le q\}$, we get
\begin{align*}
\mathbb P(Y\le q)=1.
\end{align*}
If $q\in\mathbb Q$ and $q<c$, then $q$ cannot belong to the defining set for $c$, so $\mathbb P(Y\le q)\ne1$. But this probability is either $0$ or $1$, hence
\begin{align*}
\mathbb P(Y\le q)=0.
\end{align*}
Now countability of $\mathbb Q$ lets us pass from rational thresholds to the random variable itself:
\begin{align*}
\{Y<c\}=\bigcup_{\substack{q\in\mathbb Q\\ q<c}}\{Y\le q\},
\end{align*}
so $\mathbb P(Y<c)=0$. Also,
\begin{align*}
\{Y>c\}=\bigcup_{\substack{q\in\mathbb Q\\ q>c}}\{Y>q\},
\end{align*}
and each event $\{Y>q\}$ has probability $0$, because $\mathbb P(Y\le q)=1$ for every rational $q>c$. Therefore $\mathbb P(Y>c)=0$. Combining the two estimates gives $Y=c$ $\mathbb P$-a.s.[/guided]