On page 3 of Knuth's Pre-Fascicle 5A (Mathematical Preliminaries Redux) of TAOCP, it reads:
... you might think of $E(X \mid Y)$ as a function of $Y$. Well, yes; but the best way to understand $E(X \mid Y)$ is to regard it as a random variable.
and
All random variables are functions of the atomic events $\omega$. The value of $E(X \mid Y)$ at $\omega$ is the average of $X(w')$ over all events $\omega'$ such that $Y(\omega') = Y(\omega)$: $$E(X \mid Y)(\omega) = \sum_{w' \in \Omega} X(\omega') \Pr(\omega')[Y(\omega') = Y(\omega)]/\Pr(Y = Y(\omega)).$$
How to understand the formula for $E(X \mid Y)(\omega)$?
Specifically, is it a definition or is it derivable from some basic facts and definitions? Why does it involve all $\omega'$ such that $Y(\omega') = Y(\omega)$?
Furthermore, suppose that $Y(\omega) = y$, I find that $$E(X \mid Y)(\omega) = E(X \mid Y = y),$$ according to the formula above.
Is it correct? If so, how to understand it, for example, from the perspective of function composition?
The formula for $E(X|Y)(\omega)$ is given and is clearly a function of $X(\omega)$ and $Y(\omega)$. Thus it is a function of another random variable and hence a random variable itself. This random variable represents conditional expectation. The formula gives you a way to compute it as well.
The formula states that the conditional expectation (random variable $E(X|Y)$) is given as the probability weighted sum of the random variable $X(\omega')$ on all $\omega'$ for which holds $Y(\omega')=Y(\omega)$ or in other words by the formula $$E(X|Y)(\omega)=\sum_{\omega' \in \Omega}X(\omega') Pr(\omega'|Y(\omega))$$