Excerpt from The New Yorker article:

In recent years, psychologists and neuroscientists have redeemed this mental state, revealing the ways in which mind-wandering is an essential cognitive tool. It turns out that whenever we are slightly bored—when reality isn’t quite enough for us—we begin exploring our own associations, contemplating counterfactuals and fictive scenarios that only exist within the head.

Virginia Woolf, in her novel “To The Lighthouse,” eloquently describes this form of thinking as it unfolds inside the mind of a character named Lily:

Certainly she was losing consciousness of the outer things. And as she lost consciousness of outer things, her mind kept throwing things up from its depths, scenes and names, sayings, memories and ideas, like a fountain spurting.

A daydream is that fountain spurting, spilling strange new thoughts into the stream of consciousness. And these spurts turn out to be surprisingly useful.