Such non-constant $f$ does not exist if $K$ is a sufficiently large ball, unless $n = 1$ (in which case $\exp(M^2 p^2)$ is an example).
Indeed, suppose that $K$ contains a ball of radius $R > \tfrac{1}{M}$ and $f$ satisfies the desired condition; that is, the quadratic form $D^2 f(p)$ is greater than $M \|D f(p)\| \times \|h\|^2$ at each $p \in \mathbb{R}^n$. In particular, $f$ is a convex function.
Define $g(r)$ to be the average of $f$ over the sphere $\{p \in \mathbb{R}^n : \|p\| = r\}$. It is then not very hard to see that the function $g(\|p\|)$ also satisfies the desired condition (see below). By evaluating this condition for $p = (r, 0, 0, \ldots, 0)$ and $h = (0, 1, 0, 0, \ldots, 0)$ we find that
$$ \frac{g'(r)}{r} \geqslant M |g'(r)| , $$
which is, of course, not possible when $r > \tfrac{1}{M}$ unless $g'(r) = 0$.
It follows that $g$ is constant on $[\tfrac{1}{M}, R)$. This, however, implies that $f$ is an affine function on $B(0, R) \setminus B(0, \tfrac{1}{M})$ (again, see below). We conclude that $D^2 f(p)$ is identically zero in $B(0, R)$, and so $D f(p)$ is identically zero in $B(0, R)$, that is, $f$ is constant in $K = B(0, R)$.
Regarding the first "see below": the easiest way to see that $g(\|p\|)$ has the desired property is to use the expression
$$
g(\|p\|) = \int_{SO(n)} f(O(p)) dO ,
$$
where $SO(n)$ is the class of all orthogonal matrices and $dO$ is the uniform measure (that is, the Haar measure) on $SO(n)$. The above integral does not increase the gradient (the gradient of $g(\|p\|)$ is not greater than the supremum of $\|D f(q)\|$ over $q$ such that $\|q\| = \|p\|$) and does not decrease the quadratic form (the second derivative of $g(\|p\|)$ is the average of matrices similar to $D^2 f(q)$ over $q$ such that $\|q\| = \|p\|$).
The other "see below" follows from the inequality
$$
f(p) + f(-p) \geqslant f(\tfrac{r}{R} p) + f(-\tfrac{1}{M} p) \tag{$\star$}
$$
for every $p$ with $\|p\| = R$ and every $r \in [0, R]$. This inequality is strict unless $f$ is linear on the interval $[-p, p]$. Integrating the above inequality over $p$ leads to $g(r) \leqslant g(R)$, with equality if and only if equality in ($\star$) holds for almost every $p$. It follows that $f$ is affine on almost all intervals $[-p, p]$ with $\|p\| = R$, and using again convexity of $f$ it is not very hard to see that $f$ is necesarily affine on $B(0, R)$.