They can read the HTTP referrer header containing the search string.
Simplification of simplification: someone clicks a link on a Google search results page (which has a search query as part of the URL) to another page. On this page you can read the URL of the previous page (it was a Google search).
Using the same technique, web developers can discover which pages link to their page.
source share