The autocovariance is defined as
$$\gamma(t,s) = Cov(X_{t}, X_{s})=E[(X_{t}-\mu_{t})(X_{s}-\mu_{s})]$$
When we have a stationary process the only thing that matters is the lag between the variables:
$$\gamma_{k} = Cov(X_{t}, X_{t-k})=E[(X_{t}-\mu)(X_{t-k}-\mu)]$$
However, the expectation means that we are summing over all possible values of the random variable $X$. For example:
$$\gamma_{k}=\int\cdot\cdot\cdot\int(X_{t}-\mu)(X_{t-k}-\mu)f(X_{t},...,X_{t-k})dX_{t},...,dX_{t-k}$$
Given this definition of $\gamma_{k}$, how can we derive the sample autocovariance:
$$\gamma_{k} = \frac{1}{N}\sum_{t=0}^{N}(X_{t}-\mu)(X_{t-k}-\mu)$$
in which we are summing over $t$ instead of $X$. I think this is related to an ergodicity assuption, but I haven't found a very detailed explanation about it.
Another question: Is this definition of sample autocovariance correct only when the process is stationary?