Despite being a romantic, who emphasized emotion over reason, that is to say that Keats relied on his emotions rather than his intellect when writing his poetry, Keats was suffering from tuberculosis which eventually took his life at twenty-five, and age is a factor in ones perceptions of life, and death. So being young, a romantic, and aware of his malady, Keats' tone in much of his poetry is fraught with melancholy. He faced death each day. One of his more famous poems "When I Have Fears That I May Cease to Be" addresses this.
The reason why Keats denotes melancholy in his work is because the use of nostalgic and melancholic literary devices is a typical practice among poets and writers of the Romantic period. Keats is one of the greatest in his genre, and one of the most significant representatives of this literary movement.
This practice is also part of his philosophical view of poetry, which should be able to include
"negative capability," the truth of Imagination, and "soul-making."
These three capacities are for the poet to give himself completely to the imagery and essence of the poem, to ellaborate in the sensitivities of life, and to make poetry a live-changing project of art.
Additionally, Romantic and Gothic writers include other elements to their works: Nostalgia, melancholy, the supernatural, inevitability of fate, tragedy, sadness, deterioration, the ruin of the soul, and the feeling of longing.
Some additional Romantics/Gothic authors include Oscar Wilde, Edgar Allan Poe, Lord Byron, and Mary Shelley, among others.
Keats had a hard life, marred by many tragedies, deaths, health challenges, failed career, etc. There is an excellent online article about his life at the link below.