The are many kinds of mimicry in nature. A few examples are the creatures which resemble tree bark, twigs, fresh green leaves, curled-up dead leaves, flowers, rose thorns, seaweed fronds, stones, or bird droppings. Some resemble another species that tastes bad, or another species that has a poisonous bite.
Click to look more closely at a mimic
Evolution explains this by saying that mimicry can be improved slowly. It can become better in many small steps, taken one by one across a great many generations. Each step gives a small benefit, as required by a Darwinian gradualistic scenario.
Predators (or prey) do not have perfect eyesight, or perfect intelligence either. They will not necessarily see through a bad disguise. Furthermore, the conditions for seeing aren't always perfect. Cloudy days aside, there is a gradation between noon and twilight. Nor is the viewing distance always the same. Sometimes the mimic is seen close up, but sometimes it is seen from a great distance. Sometimes the viewer is in a hurry, and looks briefly. Perhaps the viewer doesn't look directly at the mimic. A mimic is occasionally seen against a nice uniform background, but the view in a natural setting is usually full of clutter. And then there's the old joke about the person stopping to lace up his sneakers while running away from a bear. ("I don't have to be faster than the bear: I only have to be faster than you.") Mimicry is useful as long as you are a better mimic than the guy beside you.
Each of the above reasons means that there is a continuum. At the bad-mimicry end of the continuum, the mimicry would only rarely make a life-or-death difference. At the perfect-mimicry end of the continuum, the mimic is safe even when a predator takes a close look. Wherever a creature falls on this continuum, it has a corresponding chance of benefit. And, an improved mimic has a slight edge over the others of its kind. We have a Darwinian scenario, where statistics is on the side of making any accidental mimicry get better and better.