Another way to look at this integral is through the random variable transformation point of view. You can think of $Y=f(x)$ as a new random variable, and your integral is the expectation (mean) $E[Y]$ of the new variable $Y$.
Let's build the probability density function of the new variable $Y$. Unfortunately, we can't derive an analytical expression. We'll have to use a more complex, integral form of it.
What is the probability that $Y$ will have values between $y$ and $y+dy$? We look at all $x$ where $y<f(x)<y+dy$ and add up their probabilities: $$g_y(y)=\int_{x:y<f(x)<y+dy}g(x)dx$$$$g_y(y)dy=\int_x \mathbb1_{y<f(x)<y+dy} g(x)dx $$
Next, we simply integrate over all values of $Y$: $$E[y]=\int_yyg_y(y)dy$$ Since $\int_y$ runs through all possible $y$, it's the same as running the integral through all possible $x$. Just Just pause for a moment and agree with me...
Now that you agreed with me you'll see that: $$E[Y]=\int_xf(x)g(x)dx$$