We prove general Dwork-type congruences for Hasse--Witt matrices attached to tuples of Laurent polynomials. We apply this result to establishing arithmetic and $p$-adic analytic properties of functions originating from polynomial solutions modulo $p^s$ of Knizhnik--Zamolodchikov (KZ) equations, solutions which come as coefficients of master polynomials and whose coefficients are integers. As an application we show that the $p$-adic KZ connection associated with the family of hyperelliptic curves $y^2=(t-z_1)dots (t-z_{2g+1})$ has an invariant subbundle of rank $g$. Notice that the corresponding complex KZ connection has no nontrivial subbundles due to the irreducibility of its monodromy representation.