Suppose that $p \geq 2$ is an integer with the following property: If $m$ and $n$ are integers and $p|mn,$ either $p|m$ or $p|n.$ Show that $p$ is prime.
Assume that $p$ is not prime. Then $p = xy,$ for some integers $x,y.$ Then, the statement "If $m$ and $n$ are integers and $p|mn,$ either $p|m$ or $p|n."$ is not necessarily valid, for it is possible that $x|m, x \nmid n$ and $y|n, y \nmid m,$ in which case $xy|nm,$ but $xy \nmid n$ and $xy \nmid m.$
Does this proof work? My instincts are telling me that it's lacking. But, I don't trust my instincts.
I propose the following way, simpler in my opinion, using your idea: suppose $\;p\;$ is not a prime, then $\;p=xy\;,\;\;1<x,y<p\;$.
But then $\;p\,\mid xy(=p)\;$, yet it can't be that $\;p\,\mid x\;$ or $\;p\,\mid y\; $ as both $\;x,\,y<p\;$...!