Tolkien was trying to write a mythology - it’s meant to be a mythological past for our actual world. It isn’t set in the medieval era of our world though, it’s meant to be timelessly ancient. Myths set in an ancient past often are told with protagonists who seem to come from a more recent time though. Consider Saint George and the Dragon - a 12th century myth about a knight in shining armor who ‘long ago’ fought a dragon. A knight - a saintly one in particular - was a contemporary character but the story was set in the ancient past of legend. Similarly the ancient Greeks told legends about the Trojan wars where characters who resembled their contemporary warriors fought alongside gods.
The anachronism is part of the form. The shire isn’t ’medieval’ or ‘feudal’, it’s timelessly rural or * bucolic*. Hobbits are in behavior far more like 19th century farmers than medieval peasantry and that’s appropriate because they are meant to represent a nostalgic persona to an early 20th century audience, even though they are participating in a story that is meant to take place in a nebulous prehistory, before the world changed.
The journey in the Lord of the Rings is almost as much a journey back through deeper and deeper legend as it is through space - the hobbits travel from a Napoleonic era Shire, through Renaissance Rivendell, back to a medieval Rohan then classical Gondor, and then into the strictly mythological Mordor.