In most High Fantasy novels, authors usually invent languages (or at least parts of languages) for their characters to use. These languages usually exist to help the world created by the novel, and not the other way around. However, Tolkien wasn’t really a writer as much as he was a linguist.
Tolkien was a specialist in Old English and was obsessed with many different languages; he even helped write a Dictionary! At some point he started creating his own languages. However, he thought that part of what defines any language is its history. For a language like Spanish, you can trace back origins of words, and you can see how certain events in the history of Spain have molded and changed the language.
For Tolkien, an invented language had to have a back story to be real. That’s why he started writing the stories that became the Silmarillion, and eventually The Lord of the Rings: they were supposed to be the history that explained how all his different languages were formed and evolved.