Mike is correct. There are instances where mushrooms are not dried quickly enough, a particular bacteris grows on the moist cap, produces toxins and then is dried. This csn easily cause stomach priblems that are attributed to the mushroom itself.
Not to say that all stomach upset is caused by bacteria. The chitin in the mushroom is said to have gastric effects but i suspect there are other compounds as well. What i do know is that contrary to mescaline, psilocybin does not inherently cause stomach problems