Setup
Let us use the following model for a Completely Randomised Designed (CRD) experiment:
$$ Y_{ij}= \mu + \tau_i + \epsilon_{ij}$$ where the errors $\epsilon _{ij}$ ~ Normal ($0, \sigma ^2 $) and are independent (and uncorrelated). Here, $i$ refers to a particular treatment where $i = 1 . . .t$ and $j$ refers to the $j$th observation of the $i$th treatment and $j = 1 . . .n_i$.
If we want to find Least Squares Estimates for $\mu$ or $\tau _i$ (for a fixed $i$) , then we need to minimise the sum of the squares of the errors. In other words, we want to minimise:
$$ S =\sum _{i=1}^t \sum _{j=1}^{n_i} \epsilon _{ij}^2 = \sum _{i=1}^t \sum _{j=1}^{n_i} (Y_{ij}-\mu - \tau_i)^2 $$
We can then look to find a suitable value of $\mu$ or $\tau_i$ (for a fixed $i$) respectively by trying to the value of that variable that minimises the sum.
Attempt
In order to minimise this sum, we first differentiate with respect to the variable of choice. If this is $\mu$, we get:
$$ \frac{ \partial S}{\partial \mu} = -2 \sum _{i=1}^t \sum _{j=1}^{n_i} (Y_{ij} - \hat{\mu} - \hat{\tau}_i) = \color{red}{ -2 \sum _{i=1}^t \big{(}\sum _{j=1}^{n_i}(Y_{ij} - n_i \hat{\mu} - n_i \hat{\tau} _i) \big{)}} = 0$$
Question
My question is about what the justification is for the step in red.
I'm sure I'm overlooking something obvious, but I can't see why we can multiply $\mu$ and $\tau _i$ by these constants and have the sums remain equal. This is part of the solution in my textbook (and a similar principle is used for minimising with respect to $\tau _i$) and I would be interested in an explanation of why we are able to do this.