Derivation (test for homogeneity)
Under $H_0$, the maximum likelihood estimators $\hat p_{y}^{(0)}$ maximises $$ \begin{align*} l(\hat p_y^{(0)}) = \sum_{x,y} N_{xy} \log \hat p_y^{(0)} = \sum_{y=1}^{c} \underbrace{\left(\sum_{x=1}^{r} N_{xy}\right)}_{N_{+y}} \log \hat p_y^{(0)} \end{align*} $$ subject to $\sum_{y} \hat p_y^{(0)} = 1$ and $\hat p_{y}^{(0)}\geq 0$. As before we have $$ \begin{align*} \hat p_y^{(0)} = \frac{N_{+y}}{n}. \end{align*} $$
Now under $H_1$, the maximum likelihood estimators $\hat p_{y\mid x}^{(1)}$ maximises $$ \begin{align*} l(\hat p_{y\mid x}^{(1)}) = \sum_{x=1}^{r} \sum_{y=1}^{c} N_{xy} \log \hat p_{y\mid x}^{(1)}. \end{align*} $$ subject to $\sum_{y} \hat p_{y\mid x}^{(1)} = 1$ and $\hat p_{y\mid x}^{(1)}\geq 0$. As each row follows an independent multinomial distribution, we can maximise each row separately to get $$ \begin{align*} \hat p_{y\mid x}^{(1)} = \frac{N_{xy}}{n_x}. \end{align*} $$
Substituting into the likelihood ratio, $$ \begin{align*} 2\log Λ = 2\sum_{x,y} N_{xy} \log \frac{N_{xy}/n_x}{N_{+y}/n} = 2\sum_{x,y} N_{xy} \log \frac{N_{xy}}{n_x N_{+y}/n}, \end{align*} $$ so we have $O_{xy} = N_{xy}$ and $E_{xy} = n_x N_{+y}/n$.
$H_1$ has $rc$ variables ($p_{1\mid 1}, \ldots, p_{c\mid 1}, \ldots, p_{1\mid r}, \ldots, p_{c\mid r}$) and $r$ constraints ($1=\sum_{y} p_{y\mid 1} = \ldots = \sum_{y} p_{y\mid r}$) so $rc-r$ degrees of freedom. $H_0$ has $c$ variables ($p_{1}, \ldots p_{c}$) and $1$ constraint ($\sum_{y=1}^{c} p_y = 1$), so $c-1$ degrees of freedom. Thus $$ \begin{align*} d = (rc-r) - (c-1) = (r-1)(c-1). \end{align*} $$