The reason that $p(x)$ is equal to the zero polynomial in $\Bbb Z_4[x]$ is that $4,8,$ and $-16$ are all equal to $0$ modulo $4.$ That is, they are all integer multiples of $4,$ so have a remainder of $0$ when divided by $4.$ However, $q(x)$ is not equal to the zero polynomial in $\Bbb Z_2[x],$ since $1$ is not an even number.
More generally, if we are given a polynomial $f(x)=\sum_{k=0}^na_kx^k\in\Bbb Z_m[x],$ where each $a_k$ is an integer, then for each $k,$ there is a unique integer $0\leq b_k<m$ such that $a_k-b_k$ is an integer multiple of $m.$ $g(x)=\sum_{k=0}^nb_kx^k$ is then equal to $f(x)$ in the ring $\Bbb Z_m[x],$ and $f(x)$ is equal to the zero polynomial if and only if each $b_k=0.$