How does the eye know whether to focus further out or nearer in order to bring a blurry object into focus?
The neurology of vision is an extremely complex subject and is difficult to describe with any brevity, because there is so very much going on in so many parts of the brain. It is estimated that about 50% of the pathways of the brain, and about 30% of the cortex are involved in vision (where only 8% of the cortex is devoted to touch, and 3% to hearing). Some research estimates that eighty to eighty five percent of our perception, learning, cognition and activities are mediated through vision.1

The ability to accurately focus on an object, sustain that focus, and to change focusing when looking at different distances is called accommodation. That happens with the pupil size, the lens shape, etc. but it doesn't tell us how the brain chooses on what to focus. The short answer is that it's much more than focusing like a camera lens. We have retinal areas that simultaneously pay attention to further and closer areas, light/dark, edges, and more, all going on at once. That and much more information carried to the brain is processed, and efferently focus is honed. It's even more complex when two eyes are involved.

There are so many aspects to sight that an enormous number of kinds of optical illusions exist. They are involuntary. That's why they're fun. In fact, if you weren't tricked, it would indicate a problem in part of your brain. Here's one that relies on processing contrast:



As you scan looking at the white dots, your peripheral vision seems to be able to see black dots, but it's clear on scanning them one row at a time that there are no black dots.

In the following illusion, the red vertical lines are parallel.



The following are summaries of the neuroanatomy of vision.

Eye, Brain and Vision
Anatomy and physiology of the afferent visual system

1 Vision Is Our Dominant Sense