A very shrewed strategy by the Brits. They could have annihilated the Barbary pirates any time they wanted, but they chose to pay them tribute so the pirates would harass everyone else's shipping.
It was the same strategy they used with the "Pirates of the Caribbean," who were allowed to refit their ships in British ports . . . until the pirates started to attack British shipping.