Sexually deceiving plants

What really used to confuse me was insects that mimic plants – e.g., this katydid species looks like a leaf, that katydid species looks like a lichen. I wondered, how do they know what they look like? How does the leaf-mimic katydid know that it looks like a leaf, and how does the lichen-mimic katydid know that it looks like a lichen? The explanation I was given is that they don’t – the leaf-mimic katydid doesn’t know that it looks like a leaf; it just has an instinct for staying among leaves, which evolved in the same way and over the same span of time as its leaf-like appearance did.