Monte Carlo Importance Sampling
During the implementation, the way rays are scattered does not actually change and remains random.


Actually the way rays are scattered does change, specifically when you sample a light. In chapter 8 he makes a mixture pdf in order to sample either the light or the bsdf.


  What changes looks to be the contribution of each ray.


This does change, but not specifically due to the sampling of the lights but rather due to importance sampling. But that was already introduced in chapter 4.

Basically you have the following:
$$I = \int_{\Omega}f(x)\,dx = \int_{\Omega}\frac{f(x)}{p(x)}p(x)\,dx = E\left[\frac{f(X)}{p(X)}\right] = \frac{1}{N}\sum_{i=1}^{N}E\left[\frac{f(X_i)}{p(X_i)}\right] \approx \frac{1}{N}\sum_{i=1}^{N}\frac{f(x_i)}{p(x_i)}$$
Where $X$ and $X_i$ are distributed according to the probability density $p$.
As evident the main difference to the Monte Carlo formulation you are probably used to is the $p(x)$ factor, and the fact that $x_i$ are not uniformly sampled but rather sampled according to $p$. Note that for uniform sampling $p(x)=1$ and the equality still holds. Thus this is simply a generalization.