It is OK. Sometimes a coral will eat stuff and spit out remaining stuff that it cannot digest.
The shrimp is scavenging for bits of food that the coral is spitting out.
The shrimp does not know (or care) whether the food is on its way into the coral's mouth or on its way out.