This question has been plaguing scholars for generations. With Thucydides being the only contemporary source for most of the events he describes, it is often impossible to know for certain to what extent he was reporting the facts. The speeches are a particularly controversial topic. On the one hand, he may have been present at several of them, or they may have been reported to him; on the other hand, who can remember a speech verbatim?
In one of the most debated passages of his entire work, Thucydides specifically addresses the problem of recording speeches:
With reference to the speeches in this history, some were delivered before the war began, others while it was going on; some I heard myself, others I got from various quarters; it was in all cases difficult to carry them word for word in one's memory, so my habit has been to make the speakers say what was in my opinion demanded of them by the various occasions, of course adhering as closely as possible to the general sense of what they really said.
-- Thuc. 1.22.1
Modern scholars are endlessly going back and forth over what these lines mean. Some see them as a sign that Thucydides was trying his very best to reconstruct the exact words of every speech, while others interpret his words as an admission that he pretty much made it all up.
In practice, we have no choice but to consider what is plausible in each case. Was Thucydides there, or could he have spoken to someone who was there? Is what he wrote likely to have been said at that time, or does it seem artificial or loaded with hindsight? What was Thucydides trying to achieve in his narrative by including the speech? The answers to such questions help us narrow down how reliable a particular speech is likely to be.
In the case of the debate at Sparta, it is entirely possible that he is being truthful about who spoke, but it is much more doubtful that he wrote down exactly what they said. In my view (though I'm sure there are those who would disagree) it is too clearly a part of Thucydides' programme of setting up a contrast between the character of the Athenians and the Spartans to be accurate. The speeches are also laced with foreshadowing about the events of the war. Thucydides' speeches should always be taken with a grain of salt, but in this particular case, where he is setting up the contrast between states that made the Peloponnesian War inevitable in his eyes, we should be especially careful not to take the words of the Corinthians, Athenians and Spartans at face value.