Suppose a 2-D grid of size n*n. For simplicity, suppose border cells are adjacent with border cells of other side, That is each cell in this grid has exactly 8 neighbors.
Now color of each cell is with equal probability of 0.5 black or white. What is the expected number of cells which are same color with all of their 8 neighbors?
For each cell, $(i,j)$, let $A_{i,j}$ be the event that cell $(i,j)$ and all of its neighbors are the same color. If $N$ is the total number of such cells, then $$ N=\sum_{i,j}1_{A_{i,j}}, $$ where $1_A$ is the indicator variable for event $A$.
Then linearity of expectation yields that $$ \mathbb{E}[N]=\mathbb{E}\left[\sum_{i,j}1_{A_{i,j}}\right]=\sum_{i,j}\mathbb{E}[1_{A_{i,j}}]=\sum_{i,j}P(A_{i,j}). $$ Can you see where to go from here?
The big moral of the story is that although the events $A_{i,j}$ are clearly not independent, in some sense the expectation just doesn't care. As long as you can view your variable as the sum of separate contributions (independent or no), linearity of expectation allows you to break the total down into its constituent probability contributions.