Failure of Doob-Dynkin lemma in general measurable spaces
As the composition of measurable functions remains measurable, one direction always holds. So what must fail is the other direction.
Now let $\Omega_1 = \{\omega_1, \omega_2\}$ and consider $f : \Omega_1 \to \Omega_2$ with $\Omega_2 = \{1,2\}$ and $f(\omega_1) = f(\omega_2) = 1$. We take $\mathcal F = \{\emptyset, \Omega_2\}$ as our $\sigma$-algebra, then $\sigma(f) = \{ f^{-1}(\emptyset), f^{-1}(\Omega_2) \} = \{\emptyset, \Omega_1\}$. Also take $\{\emptyset, \mathbb R\}$ as the $\sigma$-algebra on $\mathbb R$ (note that intuitively it is too coarse to "distinguish" the values a measurable function takes), then any function $h : \Omega_1 \to \mathbb R$ is measurable with respect to $\sigma(f)$ on $\Omega_1$ and the $\sigma$-algebra $\{\emptyset, \mathbb R\}$ on $\mathbb R$. But for example for $h(\omega_1) \ne h(\omega_2)$ there is no function $g : \Omega_2 \to \mathbb R$ with $h = g\circ f$, as $g(f(\omega_1)) = g(f(\omega_2))$.
The statement remains true if $\mathbb{R}$ is replaced with a separable, complete metric space. See Kallenberg's book, Lemma 1.13.