Why are eggs laid near aphids, other plant pests, and caterpillars? Simple. Butterflies and moths are attracted to their host plants by scent.
When an aphid or other plant pest (including caterpillars) eat or drink from the plant, they damage the plant, releasing its scent. The scent is strongest where it is being actively damaged. Sometimes they actually lay an egg on the plant pest, like this Monarch butterfly egg laid on an aphid.
This Sleepy Orange butterfly caterpillar has three Sleepy Orange eggs on it.
We often see Gulf Fritillary butterflies laying eggs close to an area or actually where there are caterpillars actively feeding. In the third photo, we see a Gulf Fritillary butterfly laying eggs on my hand. After cutting passion vine to feed caterpillars, my hand was covered with passion vine scent. She came to my hand and laid three eggs. In the photo, she is laying the second egg.
Keep an eye out in your garden. When a butterflies comes in to lay eggs on a plant with caterpillars, do they first tend to fly to the area of the plant where a caterpillar is feeding?