Arthur Conan Doyle frequently inserted such anecdotes in his stories. They help to characterize both Holmes and Watson. Holmes cannot help observing, analyzing and deducing. His mind is always at work. Watson tries to emulate him because he admires him, but Watson lacks the requisite mental capacity. Private detective stories typically begin with someone coming to the detective with a problem (e.g. Brigid O'Shaughnessy coming to Sam Spade in The Maltese Falcon). The author tries to make these obligatory scenes somewhat different (e.g. Philip Marlowe goes to see General Sternwood in the greenhouse where the old man raises orchids). The opening of the Hound of the Baskervilles would be less interesting and less realistic if the owner of the walking stick simply knocked at the door, entered, introduced himself, and commenced to tell about the mysterious hound. Doyle was a very good fiction writer and he knew how to create atmosphere and verisimilitude with the delicate use of details. He draws the reader into the long story about the Hound of the Baskervilles so that the reader believes he is experiencing the scenes and events himself. This is what we want in fiction: we want to be hypnotized and carried away from our monotonous existence.
The prototype of the Sherlock Holmes stories was Edgar Allan Poe's "The Murders in the Rue Morgue." It is worth referring to this story to see how Poe spent many pages on incidental matters before launching into the investigation of the murders. See the reference link to Poe below.