You can retreat to any province that is open, hasn't been fought over (i.e. bounced in), and wasn't the province the unit was attacked from. You also have the option of voluntarily destroying the unit rather than retreating. If there are no open spots to retreat to, it automatically blows up your unit.
It doesn't matter what territory it is or who owns it so long as it follows those rules.
