Actually, the reason is that both the operators ${d\over dt}$ and $\int$ are linear operators over the functions space which we will recall as $F$. The reason is easy. For the derivative operator we have $$\forall f_1,f_2\in F\quad,\quad {d\over dt}(af_1+bf_2)=a{d\over dt}f_1+b{d\over dt}f_2$$and for the integral $$\int_X af_1+bf_2=a\int_Xf_1+b\int_Xf_2$$
The general result is that
$$\text{Any two linear operators can be swapped over the operands.}$$
The concept of expected value
As intuition says, to obtain a simple average from a set of data, we sum the data up and divide the result over their total number. Say, the data $\{x_1,x_2,\cdots ,x_n\}$ are given. The average of these data, which we denote by $\bar x$, becomes$$\bar x={1\over n}\sum_{i=1}^{n}x_i$$similarly for a continuous data such as a function like $g(x)$, the average over an interval $[a,b]$ becomes $$\bar g={1\over b-a}\int_a^b g(x)dx$$as long as the integral exists and is bounded.
To some reasons, one subset of data matters to us more than the others so as they must also be more determining in the total average. To respect this case, we define a weighted average with a weight function $f(x)$ to apply to $g(x)$. The weighted will then become$$\bar g_w=\int_a^b{g(x)f(x)dx}$$where$${\int_a^b f(x)=1\\f(x)\ge 0\quad,\quad x\in [a,b]}$$The mathematical expectation of a function $g(x)$ under the PDF of a random variable is then defined as $$E\{g(x)\}=\int_Xg(x)f(x)dx$$where the PDF $f(x)$ actually determines which parts of $g(x)$ matter more and which matter less.