The pest concentrates on it and leaves the crop you care about in relative peace. A common example is the nasturtium, which attracts blackfly (black bean aphid).
It works if you keep an eye on it: when the trap plant is heavily infested, remove it or clean it before the pest breeds and spreads to the rest of the garden.

