% Chance to Cast When Struck isn't applied if the attack misses, or if it is subsequently blocked.
It's applied whenever the user is hit by a melee attack (excluding charging Claw Vipers and Reanimated Horde), a missile attack applying weapon or monster damage, persistent traps or fires, or exploding barrels.
It's not applied by missiles which only apply their own damage or skill damage. Most of the applicable missile attacks are intuitive (the user is hit by a visible arrow, bolt, dart, javelin, quill or throwing weapon), but others are less obvious:
Tainted lightning orbs
Skeleton Mage bolts
Lightning Spire bolts
Willowisp lightning bolts
Imp fire bolts
Claw Viper missiles
Succubus and Stygian Witch bolts
It's also not applied by returned damage or death explosions.