But I want the attacker get stunned after the spell is applied to the user, so the attacker only gets stunned if they attack the user.
You can do it with
Yanfly's Weapon Animation plugin
Here's how I would do it :
The enemy casts "Thunder dome" and gains the state "Electric barrier". If I understand, any physical damage dealt to the enemy causes the attacker to be stunned.
In the state effect :
Sp-Parameter Physical Damage Rate 0% (only if you want the enemy to take no damage in addition of counterattacking and stunning the attacker)
Ex-Parameter Counterattack Rate 100% (The enemy will ALWAYS stun anyone trying to attack it)
Attack State Rate : Stunned 100%
With YEP Weapon Animation you can put that in the notetags :
<Weapon Animation: x>
It will temporary replace the basic attack animation (which plays while counterattacking) by one of your choice, like a thunder animation.
I tested it, and it works !