Transfer function and difference equations: why does $H(z)$ numerator polynomial not correspond to $Y(z)$?
It is right that $H(z)=\frac{Y(z)}{X(z)}$ and yes, the output is in the numerator. But the numerator of one side is multiplied by the denomarator of the other side to get an equality:

$$H(z)=\frac{b_Mz^M+\cdots+b_0}{a_Nz^N+\cdots+a_0}=\frac{Y(z)}{X(z)}\tag{0}$$
$$\hspace{-1.5cm}\Rightarrow\left(b_Mz^M+b_{M-1}z^{M-1}+\cdots+b_0 \right)X(z)=\left(a_Nz^N+a_{N-1}z^{N-1}+\cdots+a_0\right)Y(z)\tag{1}$$
Taking the inverse $z$ transform from $(1)$ yields the differnce equation of the system:
$$b_Mx[n+M]+b_{M-1}x[n+M-1]+\cdots+b_0=a_Ny[n+N]+\cdots+a_0\tag{2}$$
So indeed, I explained it in the reverse order. Everything begins from the difference equation of a system in $(2)$, then the $z$-transom is applied on it:
$$\hspace{-1cm}b_Mz^MX(z)+b_{M-1}z^{M-1}X(z)+\cdots+b_0 X(z)=a_Nz^NY(z)+a_{N-1}z^{N-1}Y(z)+\cdots+a_0Y(z)\tag{3}$$ and then factoring $X(z)$ on the left and $Y(z)$ on the RHS, we will get to $(1)$. From that, $(0)$ is resulted.

If we [wrongly] had
$$\frac{b_Mz^M+\cdots+b_0}{a_Nz^N+\cdots+a_0}=\frac{X(z)}{Y(z)}\tag{4}$$ then after multiplication we would  get
$$\left(b_Mz^M+b_{M-1}z^{M-1}+\cdots+b_0 \right)Y(z)=\left(a_Nz^N+a_{N-1}z^{N-1}+\cdots+a_0\right)X(z)\tag{5}$$
$$\hspace{-1.5cm}b_Mz^MY(z)+b_{M-1}z^{M-1}Y(z)+\cdots+b_0 Y(z)=a_Nz^NX(z)+a_{N-1}z^{N-1}X(z)+\cdots+a_0X(z)\tag{6}$$
and taking the inverse $z$-transform we would have
 $$\hspace{-2cm}b_My[n+M]+b_{M-1}y[n+M-1]+\cdots+b_0=a_Nx[n+N]+\cdots+a_0\tag{7}$$
which is obviously not the correct difference equation (i.e. $(2)$ that we started from).