The tribunal of Caractacus was, according to Tacitus, a huge and celebrated affair, with an assortment of prisoners from the 9-year campaign against the Britons. To transport all these men and women from Britain and arrange for the parades, etc, would have taken months at least. This long captivity would have given Caractacus the opportunity to learn Latin. Also, the speech is short and not very complex, so he could easily have learned what he needed to know to speak it.
Here is the speech as given by Tacitus:
Si quanta nobilitas et fortuna mihi fuit, tanta rerum prosperarum
moderatio fuisset, amicus potius in hanc urbem quam captus venissem,
neque dedignatus esses claris maioribus ortum, plurimis gentibus
imperitantem foedere [in] pacem accipere. praesens sors mea ut mihi
informis, sic tibi magnifica est. habui equos viros, arma opes: quid
mirum si haec invitus amisi? nam si vos omnibus imperitare vultis,
sequitur ut omnes servitutem accipiant? si statim deditus traderet,
neque mea fortuna neque tua gloria inclaruisset; et supplicium mei
oblivio sequeretur: at si incolumem servaveris, aeternum exemplar
clementiae ero.
Translation: Had my moderation in prosperity been equal to my noble birth and fortune, I should have entered this city as your friend rather than as your captive; and you would not have disdained to receive, under a treaty of peace, a king descended from illustrious ancestors and ruling many nations. My present lot is as glorious to you as it is degrading to myself. I had men and horses, arms and wealth. What wonder if I parted with them reluctantly? If you Romans choose to lord it over the world, does it follow that the world is to accept slavery? Were I to have been at once delivered up as a prisoner, neither my fall nor your triumph would have become famous. My punishment would be followed by oblivion, whereas, if you save my life, I shall be an everlasting memorial of your clemency.