It is not clear that the speaker is deep in a forest in this poem. Rather, he describes himself as on the moors and in a "lonely" place. He implies he is near a wooded area, if not a deep forest, when he says he is
beside a pool bare to the eye of heaven.
This suggests he may have come to an open area in a woods.
Whether or not he is deep in the forest or just in a bit of woods, the speaker is there because he is having uncharacteristically fearful and unhappy thoughts. He says that, usually, he is upbeat:
My whole life I have lived in pleasant thought.
He has never worried about the future, but now, all of the sudden, he is wondering what will happen to him when he grows old. He has been thinking of poets, of which he is one, and the tendency for them to end up in "despondency and madness." This idea scares him, and he is wandering around depressed.
However, he has the good fortune to run into a bent old man leaning on a stick. Although "old and poor" and forced to labor by catching and selling leeches to doctors in this time before there was any economical security for the elderly, the man is cheerful and grateful. This lifts the spirits of the speaker, who learns an important lesson in accepting life as it comes from this kindly, humble, and hardworking old man.