The 'secrets' to fishes eating invertebrates and corals outside of their noted diets in the wild is something few people really know or understand. I'll share what I know.
A fish will eat corals and/or invertebrates outside of the normal, observed diet in the wild because of one or any combo of the following:
1. One of the biggest reasons - the organism it ate was unhealthy. Nature doesn't waste precious energy, so a coral in trouble is an invitation to predators and marginal predators and even those that wouldn't consider eating such a thing.
2. The fish is undernourished -- missing something from its diet and/or not getting fed enough (quantity and/or frequency).
3. The fish is a rogue (as noted in a previous post). Each fish is and can be out of the norm -- its own personality.