Why does $n = -3(1+ \omega)$? $n$ comes from how the density of any component of the universe scales as the universe expands in the FLRW metric. For matter, $n=-3$ since the mass of matter is conserved.
$\omega$ comes from the equation of state for any component in the universe.
$$           p =  \omega ρ $$
Pressure equals omega times energy density. For matter $\omega = 0$, matter, often termed dust, has no associated pressure. And you can see how the formula in the question works.
$$
           -3 = -3(1+0)
$$
For dark energy, $n = 0$ and $\omega = -1$. That also works
$$
            0 = -3(1 + -1)
$$
But I can't for the life of me see why $n$ and $\omega$ should even be related, let alone by this formula.
 A: It comes from the continuity equation.
The continuity equation reads
\begin{equation}
\dot{\rho} = -3 H (\rho + p)
\end{equation}
Using the equation of state$^\star$, $p=w\rho$, this equation becomes
\begin{equation}
\frac{d\rho}{dt} = - 3 \frac{da}{dt} (1+w)\frac{\rho}{a}
\end{equation}
Cancelling the $dt$'s$^\dagger$, and rearranging, we get the equation
\begin{equation}
\frac{d\rho}{\rho} = -3(1+w)\frac{da}{a}
\end{equation}
which has the solution
\begin{equation}
\rho = \rho_0 a^{-3(1+w)}
\end{equation}
where $\rho=\rho_0$ when $a=1$.

$^\star$ For some reason (I honestly suspect because of sloppy handwriting), there are multiple notations used for the equation of state parameter. I was taught that the symbol is $w$, but I have also seen $\omega$ and $\varpi$ used.
$^\dagger$ More formally, you can rerarrange the equation so the left hand side is
\begin{equation}
\frac{d\rho/dt}{da/dt} = \frac{d\rho}{da}
\end{equation}
which works so long as $\rho$ and $a$ are monotonic functions of time. (Which they are in the $\Lambda$CDM model).
A: Essentially, it's energy conservation -- see e.g. https://arxiv.org/abs/gr-qc/9712019, Chapter 8 (in particular, the part around Eqns. (8.15) to (8.23)).
