How can $E(X)$be factored out of integration? Recently, I posted a question on this forum here. In the answer to the question, it was posted suggesting that $$\int_x (x - E(X)) E(Y|X) f_xdx = \int_x x E(Y|X) f_x dx - E(X) \int_x E(Y|X) f_x dx  .$$
Note: I have taken the liberty of interchanging LHS and RHS of the equation to make myself clear.
I am lost as to how $E(X)$ can be factored out of integration, since it is not a constant, but still a function of $X$.
P.S: The answer to the original post did seem to have answer that question, but I got confused regarding this later.

You have been misled by sloppy notation in the referenced answer.
Let's dissect the original integral on the left hand side, identifying the types of the mathematical objects that appear in it.  Bear in mind that capital "$X$" and small "$x$" must be distinguished.

*

*"$X$" is the name of a random variable.


*"$x$" is the (dummy) variable of integration.


*"$E(X)$" is the expectation of $X.$  By definition, it is a number.  (Presumably it is well defined and finite.)


*"$E(Y\mid X)$" is a function.  Its value at a real number $x$ is sometimes written $$E(Y\mid X)(x) = E(Y\mid X=x).$$


*"$f_x$" is a typographical error (introduced in the answer to the linked question).  It is intended to be the density of the random variable $X$ evaluated at $x,$ often written $f_X(x).$


*"$\mathrm{d}x$" formally indicates the variable of integration.


*"$\int_x$" ordinarily means to integrate over the interval $[x,\infty).$  I don't think that's intended here, because the integral needs to be evaluated over the entire set of real numbers $\mathbb R.$
Thus, we deduce that the integrand $\left(x - E(X)\right) E(Y\mid X)(x)f_X(x)$ is obtained from the four functions $x\to x,$ $x\to E(X),$ $x\to E(Y\mid X)(x),$ and $x\to f_X(x)$ by an algebraic combination.  It, therefore, is a function of $x$ which is to be integrated over $\mathbb R.$  Written in full it is
$$\int_{\mathbb{R}} \left(x - E(X)\right) E(Y\mid X)(x)f_X(x)\,\mathrm{d}x.$$
Now the distributive law of multiplication tells us the integrand can be expressed as a difference
$$\left(x - E(X)\right) \color{gray}{E(Y\mid X)(x)f_X(x)} =  (1)\color{gray}{xE(Y\mid X)(x)f_X(x)} + (-E(X))\color{gray}{E(Y\mid X)(x)f_X(x)}.$$
This is a linear combination of the functions $g:x\to x E(Y\mid X)(x)f_X(x) $ and $h:x\to E(Y\mid X)(x)f_X(x)$ (shown in gray type above) with constant coefficients $\alpha=1$ and $\beta=-E(X).$  The equation in the question attempts to express the linearity of integration; namely, when $g$ and $h$ are integrable functions and $\alpha,\beta$ are constants,
$$\int_{\mathbb{R}} \left(\alpha g(x) + \beta h(x)\right)\,\mathrm{d}x = \alpha \int_{\mathbb{R}} g(x)\,\mathrm{d}x + \beta \int_{\mathbb{R}} h(x)\,\mathrm{d}x.$$
