It does contribute to the security. In particular, the hash function $H$ must be “random prefix preimage resistant” in order to be safe from Key Only forgeries and “random prefix second preimage resistant” in order to be safe from Known Message forgeries.
By “random prefix preimage resistant”, we mean that given an output value $e$ and a random $r$, it is hard to find an $m$ such that $H(r||m)=e$ (and in the second preimage case, even if provided with an example $m$, it is hard to find a second example).
If it were easy, then we could choose an arbitrary $e$ and $s$ and (following the Schnorr validation process) compute $r=g^sy^e$ and then solve our preimage problem for $e$ and $r$ to get a message $m$ for which $(s,e)$ is a valid signature. Note that we do not necessarily have control over $m$ and so this attack is a Key Only Attack to create an Existential Forgery and the scheme would not be EUF-KOA secure.
Similarly, in the second preimage case we could take an existing signature for a message $m$ and create a second message $m’$ with $H(r||m)=H(r||m’)$. The signature $(s,e)$ for $m$ would also work as a signature for $m’$ and the scheme would not be EUF-KMA secure.