Help with understanding why we need an expectation in the loss
It's because $z$ is a random variable, and the term is a function of $z$.  So, without the expectation, the $\log$ term would be a random variable, and you can't use that as a loss; the loss needs to be a number.  You can use its mean (its expectation).