Let $(n \mid x)$ mean $1$ if $n \mid x$ and $0$ otherwise.
Let $f = (p\mid -)$ then $f: \Bbb{Z}\setminus 0 \to \Bbb{Z}/2$ is surjective and only satisfies
$$f(xy) = f(x) + f(y) + f(x)f(y), \ \forall x,y \in \Bbb{Z}\setminus 0$$
because $p$ is a prime number. I.e. if $p$ were not prime then it would fail to hold that when $p\mid xy$ then $p \mid x$ or $p\mid y$ in general.
The surjectivity part rules out $p = 0, 1$. I'm wondering if a converse is true, i.e. for any such surjective map $f$, does there exist a prime $p$ such that $f = (p \mid -)$?
I'll omit the surjectivity condition, because the analysis isn't much harder in this case.
First, let's deal with $f(1)$.
If $f(1) = 0$, then $\forall x\,\, f(x)=f(x\cdot 1)=f(x)+f(1)+f(x)f(1)=f(x)$. So, no new relations are gained.
If $f(1) = 1$, then $\forall x\,\, f(x)=f(x\cdot 1)=f(x)+f(1)+f(x)f(1)=f(x)+1+f(x) = 1$. Thus, in this case $\forall x\,\, f(x)=1$.
Now, assume that $f(1)=0$. The expression $f(x)+f(y)+f(x)f(y)$ is the standard realization of disjunction (logical or) in $\mathbb Z/2\mathbb Z$ arithmetic (which you probably already know, but it's nice to stress this explicitly); its value is $1$ precisely when at least one of $f(x),f(y)$ is $1$.
What it means is that the value of $f(n)$ is exactly determined by the values of $f(p)$ for $p | n$. So, pick any subset $S$ of primes (even empty or infinite) and define $f(x) = 1$ iff $\exists p\in S\,\,p|x$. It is then a simple induction argument that $f(x)$ so defined satisfies the desired relation.