Let $(X, \mathcal X)$ and $(Y, \mathcal Y)$ be two measurable spaces. Suppose $f: X \to Y$ is $(\mathcal X, \mathcal Y)$ measurable, and suppose that $g: X \times Y \to \mathbb R$ is $(\mathcal X \otimes \mathcal Y, \mathscr B(\mathbb R))$ measurable (where $\mathscr B(\mathbb R)$ is the Borel sigma-field over $\mathbb R$).
Is the function $h: X \to \mathbb R$ defined by $$h(x) = g(x, f(x))$$ ($\mathcal X, \mathscr B (\mathbb R)$) measurable?
This question might be a duplicate of this one, but I want to make sure that the same argument works for general measurable spaces.
The idea is that $H: x \mapsto (x, f(x))$ is measurable because both $\pi_1 \circ H = id_X$ and $\pi_2 \circ H = f$ are measurable, where $\pi_i$ are the projections and $id_X$ is the identity function on $X$. Then, $h = g \circ H$ is measurable.