$E(Y)$ is a probability theory result. That means $Y$ (written in caps) is a random variable having a density function $f_Y$. $E(Y) = \int y f_Y$. The integration is the Riemann-Stieltjes integral. In other words, if $Y$ is discrete, it boils down to a summation, if $Y$ is continuously valued, it's a standard integral. Also in probability theory, lower case $y$ is treated as a specific value in the sample space of the random variable $Y$, and it is not random. So $E(f(y)) = f(y)$ which is some arbitrary probability constant or probability differential.
When you deal with a sample, you move out of probability theory and into statistics. So if you index a vector of observations $Y_i$, we are assuming that they are observed and the goal is inference about a probabilistic quantity. You might assume, for instance, that each of the $Y_i$ in a fixed sample of size $n$, $1 \le i \le n$, is independent and identically distributed as is often the case with a simple random sample. The sample mean $\bar{Y} = \sum_{i=1}^n Y_i/n$ is a consistent estimator of $\mu_Y = E[Y]$ by the LLN, but it is a purely theoretical quantity.