Looking at the Wikipedia page for the Law of the Unconscious statistician, the main result is stated as: $$ \displaystyle \operatorname {E} [g(X)]=\int _{-\infty }^{\infty }g(x)f_{X}(x)\,\mathrm {d} x. $$
I am a bit confused by this notation. Writing $g(X)$ seems to indicate that $g$ is a function of the random variable $X$, but isn't this really $g \circ X$, where $X$ is some real valued measurable function, and $g : \mathbb{R} \to \mathbb{R}$ is a measurable function? That way, $g \circ X$ is a measurable function with the same domain and codomain as $X$, and the above expected value is defined in the same way as it would be for $X$.
If this interpretation is correct, then don't we require $g$ to be measurable, in order for this result to hold (a condition omitted from this definition).
Is my intuition correct on this one, or is there some subtlety that I am missing here?
Indeed $g(X)$ must be interpreted as a notation for $g\circ X$ and here $g:\mathbb R\to\mathbb R$ is meant to be a Borel-measurable function having indeed the same domain and codomain as $X:\Omega\to\mathbb R$.
If we would denote $Y:=g\circ X$ then its expectation is (if it exists) defined as:$$\mathbb EY=\int Y(\omega)P(d\omega)=\int g(X(\omega))P(d\omega)=\mathbb E[g(X)]$$ It can be shown that this equals:$$\int g(x)P_X(dx)$$where $P_X$ denotes the probability measure on $(\mathbb R,\mathcal B)$ that is induced by $X$ by means of:$$P_X(B)=P(X\in B)$$ It might happen that $P_X$ has a density $f_X$ w.r.t. the Lebesgue measure and in that case:$$\int g(x)P_X(dx)=\int g(x)f_X(x)dx$$Do not confuse "definition" with something that can be deduced from it. The definition of the expectation of a random variable $X$ defined on probability space $(\Omega,\mathcal A,P)$ is: $$\mathbb EX:=\int X(\omega)P(d\omega)$$ This equals $\int xP_X(dx)$ or - if there is a density - $\int xf_X(x)dx$ but these expressions do not deserve the predicate "definition".