This is because cosx is a continuous function about x, and its integral on the interval is 0, so its mathematical expectation is 0. The proof of this conclusion needs to use the basic concepts of integral and expectation in mathematics. Integral can be regarded as a special case of summation, and the expectation is to weigh and average a series of results.
For a continuous random variable, its expectation is regarded as the integral of its probability density function multiplied by its value.