Fungi, including mushrooms, do not have a nervous system, which is required for an organism to feel pain. Therefore, it is generally accepted by the scientific community that fungi cannot feel pain.
In animals, pain is a complex process involving a series of rapid-fire communications between cells in response to a harmful stimulus. This process starts with sensory receptors called nociceptors, which detect damage to the body's tissues. The nociceptors then send signals through peripheral nerves to the spinal cord and, from there, to the brain, which interprets these signals as pain.
Fungi do not possess these physiological mechanisms. They don't have a brain, sensory nerves, or nociceptors. While fungi can respond to environmental stimuli and show a form of adaptability and communication through the transmission of chemical and electrical signals, this fundamentally differs from the subjective experience of pain that animals are capable of.
This is one of the reasons why eating fungi, like mushrooms, is generally considered compatible with a vegan or vegetarian diet, which seeks to avoid causing pain or harm to animals.