Usually ‘in’.
In the US, we don’t say ‘territory’ too often. It means land that is part of a country but has some kind of different legal status. For example:
I’m in the US.
I’m in California, a state in the US. (Saying ‘territory’ would be incorrect)
I’m in Puerto Rico.
I’m in the territory of Puerto Rico. (Correctly describing that it has a different legal status)
We might use ‘on’ with ‘territory’ to emphasize ‘ground’ or if the legal status is uncertain.
‘It wouldn’t be easy to answer the question of ‘How many languages were spoken on the territory of the Roman Empire?’ (It’s a land area but not precisely defined today, and probably not in the past either.)