If $p$ does not divide $H$, then the condition is satisfied vacuously, but the conclusion holds so there is nothing to do. So assume that $p|H$.
Let $P$ be a Sylow $p$-subgroup of $H$. If $P$ is not a Sylow $p$-subgroup of $G$, then there exists a subgroup $Q$ of $G$ that contains $P$, with $[Q:P]=p$. Now consider $Z(Q)$, which is nontrivial. If $Z(Q)\subseteq P\neq\{1\}$, then letting $x\in Z(Q)$, $x\neq 1$, gives an element of $P$ (hence of $H$) whose centralizer contains $Q$ (since $x\in Z(Q)$), so $Q\subseteq C_G(x)\subseteq H$, contradicting the fact that $P$ is a Sylow $p$-subgroup of $H$ and $Q$ is of order $p|P|$. Therefore, $Z(Q)\not\subseteq P = \{1\}$.
But since $Z(Q)$ is nontrivial, and $P$ is maximal in $Q$, this implies that $Q=PZ(Q)$. Therefore, if $x\in Z(P)$, then every element of $Q$ centralizes $x$; that is, $Z(P)=Z(Q)\cap P$. Since $P$ is a nontrivial $p$-group, $Z(P)\neq \{1\}$, so we can pick $x\in Z(P)\subseteq Z(Q)$, $x\neq 1$, and again we have $Q \subseteq C_G(x)\subseteq H$, contradicting the assumption that $P$ is a Sylow $p$-subgroup of $H$ and that $Q$ is a $p$-group properly containing $P$.
In either case, the assumption that $P$ is not a Sylow $p$-subgroup of $G$ leads to a contradiction, so if $p$ divides $|H|$, then the highest power of $p$ that divides $|H|$ equals the highest power of $p$ that divides $|G|$, so $|G:H|$ is not a multiple of $p$.