I know in the wild, many times it involves the animal's shape, colors, and markings. Some people think that many fish, like angels, have different colors and markings as juveniles so that they resemble cleaners to protect them from predatory fish. Some, for example, may have blue and white stripes as juveniles which might resemble the cleaner wrasse. So, I guess it's just an instinctual thing...they just know, or think they know, based on the phenotype of the fish, which in fact may or may not actually be a cleaner.
And it may just be a hit or miss kind of thing...one cleaner fish just happens to clean a fish one particular time without the fish initiating it. The fish then learns from this experience and seeks out cleaner fish in the future. I'm sure many a cleaner has died using this technique...haha. Or maybe the fish see a fish being cleaned and learns through observation. As kjord said...who knows!