For "an astronaut riding a horse" the system is filtering/selecting but nowhere does it understand (or claim to understand) horses or astronauts. It's giving you an image that "syntactically" agrees with other images that have been tagged horse/riding/astronaut.
The amazing bit is that we are happy to accept the image. Look closely at such images - they're always "wrong" in subtle but important ways, but we're happy to ignore that when we interpret the image.