Interesting. I knew that i wasnt supposed to go in the sun if I got lemon or lime on me. Now I know why.
All plants have defense mechanisms similar to this. Some more effective than others. Did you know the smell of cut grass that people seem to like- is actually the smell of the grass screaming? Or more technically correct is a distress response to warn other plants.
I guess it also contributes to smog. https://www.mentalfloss.com/article/30573/what-causes-fresh-cut-grass-smell
And of course hot peppers. The spicyness is a defense mechanism. But we enjoy the pain. Birds can't taste the spicyness so I guess it doesn't matter to them.
Plants are pretty fascinating.