Where does this equation for the activity in the gas phase equilibrium between N₂, H₂ and NH₃ come from?
The activity of a molecule $\ce{M}$ as a function of its concentration in the solution can be written as

\begin{equation}
  a_{\ce{M}} = \frac{\gamma_{\ce{M}} c_{\ce{M}}}{c^0} \ ,
\end{equation}

where $c^0$ is the standard concentration and $\gamma_{\ce{M}}$ is the (dimensionless) activity coefficient (see also: here and Wikipedia).
If you have a sufficiently dilute solution so that non-ideal contributions become very small, the activity coefficient can be approximated by 1, i.e. $\gamma_{\ce{M}} \approx 1$.
So, what you're left with for the activity under these conditions is

\begin{equation}
  a_{\ce{M}} \approx \frac{c_{\ce{M}}}{c^0} \ ,
\end{equation}

Now, the concentration is defined by $c = \frac{n}{V}$ and with the ideal gas law $\frac{n}{V} = \frac{p}{RT}$ you get:

\begin{align}
  a_{\ce{M}} &amp;\approx \frac{c_{\ce{M}}}{c^0} = \frac{\frac{n_{\ce{M}}}{V}}{\frac{n^0}{V}} \\
  &amp;= \frac{\frac{n_{\ce{M}}}{V}}{\frac{p^{0}}{RT}} = \frac{n_{\ce{M}} R T}{p^{0} V}
\end{align}

where $p^{0}$ is the standard pressure.