It was an allegory because, in spite of his dislike, Tolkien felt it was necessary and inevitable that it should be one.
In several lesser-known quotes, the author freely admits that the tale is allegorical. Most clearly he states:
"Of course my story is not an allegory of Atomic power, but of Power."
The Letters of J.R.R. Tolkien #186
He also claims it is a religious work which, given that it has no connection to any real-life religion, can only be true if it can be read as an allegory of religion.
"The Lord of the Rings is of course a fundamentally religious and Catholic work, unconsciously so at first, but consciously in the revision."
The Letters of J.R.R. Tolkien #142
So how do we square this circle?
The first is that another quote from Tolkien shows that he believed all myth was fundamentally allegorical in nature. Since one of his key purposes in constructing the legendarium around Lord of the Rings was to rebuild a lost English mythology it would be difficult for him not to write an allegory if this was his belief.
"I dislike Allegory - the conscious and intentional allegory - yet any
attempt to explain the purport of myth or fairytale must use
The Letters of J.R.R. Tolkien #131
He also believed that it was, to some extent, inevitable in the work of any author because it would surface through the subconscious. Or to put it another way, that allegory in literature was a failure only if it was created deliberately.
"The only perfectly consistent allegory is a real life; and the only
fully intelligible story is an allegory. And one finds, even in
imperfect human 'literature', that the better and more consistent an
allegory is the more easily it can be read 'just as a story'; and the
better and more closely woven a story is the more easily can those so
minded find allegory in it."
The Letters of J.R.R. Tolkien #109
So what are we to make of this in relation to The Lord of the Rings? His admission that the book was an allegory of power, while denying that it is one of atomic power offers a clue. In stating his dislike of allegory, he is using the term to mean a literal reading: that he dislikes stories which offer only a single, specific political or moral interpretation.
So, The Lord of the Rings can be read vaguely as an allegory of power, but not specifically of atomic power. Similarly, it can be read as an allegory of warfare, or of the struggle against evil, but not specifically of one of the World Wars. He wants his readers to relate to wide themes of human experience and not to narrow lessons on distinct events.