As I understand it, if you take a Pandora's Box near an enemy castle, the units inside will be similar to the enemy's. That is, they won't be tied to the hero's/player's race who took the Pandora's Box. They don't seem to be tied to the terrain type because one terrain type can be related to several races at once.
Справочник по НоММ-4 http://handbookhmm.ru/pamyatka-dlya-heroes-iv.html
Памятка по НоММ-3 http://handbookhmm.ru/pamyatka-dlya-homm-iii.html
и HotA http://handbookhmm.ru/vyishla-obnovlennaya-pamyatka-dlya-homm-iii-hota.html