As far as I'm aware, we still don't know why they produce psilocybin. Something that takes 30+ minutes to begin affecting you seems like a poor defense mechanism.
We know with certainty that capsaicin does act as a deterrent against consumption, and capsaicin acts immediately...
¯\_(ツ)_/¯