$$\mathcal{L}(\theta)= -\frac{1}{n}\sum_{i=1}^n \left[y_i \log(p_i) + (1-y_i) \log(1-p_i)\right]$$ When $y_i=0$, the second term is nonzero for $p_i \in (0,1)$. The factors involving $y_i$ are like a "switch." Only one of the factors involving $y_i$ is nonzero, so that is the only relevant loss term for sample $i$.