What's the purpose of colorful mushrooms' caps?
Mushroom is actually the reproductive organ of the actual fungal body beneath the surface. It have a high surface area to disperse or spread the spores.

If the eating predators are low or dispersing is not an option, then it will need other organisms to attract to that they can be spread, so they are not toxic. Analogous to fruits, they uses different colors which are non-toxic to attract.$^1$ 

Whereas brightly colored mushrooms are less toxic, whereas, most toxic ones are either brown or white.$^2$ 

Edible Mushrooms



Toxic Mushrooms:



Source:


Why do mushrooms come in so many shapes and colors?
Mushroom poisoning


Image Source:

https://www.etsy.com/listing/93680839/antique-1900-edible-fungi-print