Theres a difference between understanding and preventing, the problem is not the ai does not understand, it is that having any unit no matter what can attack freely and rampage without any consequences. If this is not changed id demand hidden nationality trait for the lanun, hippus and clan units also.
I always wondered why there are corsars but the boarding partys are not hidden nationality which would make perfect sense. The orcs could have a similar raiding unit. However each case needs an exeption, if a hidden nationality unit is killed theres X% chance they find evidence and the relations worsen etc. Something like that.
Firstly hidden nationality is not a trait, it is either from mercenaries which anyone can get, the council of esus recon units, or the Svartalfar world spell, so if you think Lanun, Hippus or Clan of Embers should get inherent hidden nationality then without losing their world spells it would be overpowered for them, and besides if they had world spells with the same effect then the world spell effect wouldn't be unique anymore.
Secondly, understanding would allow the AI to prepare an army in case of hidden nationality attack, to keep a military presence near any neighbours that may have access to hidden nationality units (such as Svartalfar), or even using hidden nationality in their own tactics to either annoy, hinder, or even weaken before war is officially declared.
There are already minor consequences to it such as maintenance for the unit, of the units death, and for the Svartalfar world spell in particular there is the part about it turning all of your units into hidden nationality, so if you were to forget the city defenders any open borders nation could easily take out your defenders. If the AI were to understand hidden nationality then it would know better to target the hidden nationality units and to use them itself, so any AI that is either Svartalfar or a possible member of the Council of Esus could always be a threat even when at peace.
Hidden nationality should be an effective tactic like it currently is, and should not have any major penalties such as a percent chance of relations worsening. As it is hidden nationality units allow you to scout out an opponents territory and to attempt to weaken them before you actually attack (or before someone else attacks, such as barbs). If this has a chance to worsen relations, and with already bad relations it could trigger war, just to see if you would be able to fight a war against that civilisation, then hidden nationality could become underpowered. One of the major bonuses of the Council of Esus right now, is not having to have a diplomacy penalty based on religion, if hidden nationality units could cause you to lose relations, then this effect would be negated and the Council could cause your relations to be worse than if you had went with a different religion from them in the first place.
Also if death of hidden nationality units could cause relations to drop, then the Svartalfar world spell could be a great hindrance, as nearby enemies could attack your hidden nationality units, before you have a chance to move them or declare nationality, giving you a chance to lose relations with another civilisation. As far as I can see no other world spell has any chance to cause a negative effect to the civilisation, so even a small chance for a negative effect could make the Svartalfar spell weaker than most of the others.