Law of mass action in a semiconductor
Because in the study of the p-n junction you assume low level injection.

Given two points x1 and x2, it can be proved that:

where n1 and n2 are the electron concentrations at x1 and x2, respectively, and phi1 and phi2 are the potentials at x1 and x2, respectively.
Applying this formula at the two edges of the depletion region in thermal equilibrium, you have then:

The subscript n means you are in n-side, the subscript p means you are in p-side, whereas the subscript 0 means you are in thermal equilibrium.
phi with subscript i is the built-in potential (and is equal to phi2-phi1).
Now, if you apply a voltage, you go out from equilibrium and you enter into quasi-equilibrium. In quasi-equlibrium, you have just to replace the built-in potential with the difference between the built-in potential and the applied voltage:

Note that the subscript 0 has been removed, since we are no more in thermal equilibrium.
In this last formula there is (I hope) the answer to your question: to write this last equation, we used the low level injection hypothesis, which says that the injection of carriers (in our case, the injection of electrons into the p-side) modifies the minority population (in our case, electrons because they are minorities in the p-side), but does not significantly affect the majority population (in our case, holes are majorities because you're in the p-side). Majority population then does not almost change and remains the same you had in thermal equilibrium (Na in our case).
Under low level injection, you can write the last equation because

where you can make the same considerations of before (holes injected into the n-side are assumed not to modify the majority population of electrons which remains thus almost constant and equal to Nd)
You can define this excess of minorities (electrons) which are injected in the p-side by taking the difference between the concentration in quasi-equilibrium and the concentration at thermal equilibrium, getting:

where

is the concentration of electrons in thermal equilibrium in the p-side at -xp. Here you are allowed to use the mass action law in thermal equilibrium to say that

Indeed, the majority population in the p-side is not significantly modified by the injection of electrons coming from the n-side, and thus remains constant and equal to Na.
From now on, you can develop all the theory to get the current flowing through the p-n junction (basically, the excess of injected electrons into the p-side is one boundary condition to solve the continuity equation into the quasi-neutral p region).
Note that all the theory is based on the low level injection approximation. If you remove this approximation, you can write the general expression of the mass action law in quasi equilibrium, which states that

where Efn and Efp are the quasi-Fermi level for electrons and the quasi-Fermi level for holes, respectively. In thermal equilibrium, the two quasi-Fermi levels coincide with the Fermi level, and thus their difference is zero: the exponential becomes equal to 1, and you obtain the well-known mass action law in thermal equilibrium.