This is a huge, game breaking issue for the late game. At present you can cast spells such as flood and curgen's inferno in a nation you're not at war with and annihilate entire cities with no reprecussions.
A solution to this problem would be as follows:
Whenever a strategic spell is cast within another sovereign's territory it invokes a diplomacy penalty for a set number of turns.
As an example: I cast Curgen's Inferno in my own territory- no AI issues. If I cast it in the territory of any other sovereign, including a non-aggression pact or ally nation they'll have a diplomacy penalty for use of that magic in their territory.
This penalty should be severe enough that if you're neutral with a faction it may force them to outright declare war on you. If trying to abuse an ally, at best you'll be able to take out one city before they break the alliance and want to immediately kick you out of their territory.