What prompts enemies to pillage improvements?

Scouts will not pillage improvements. They run around looking to find civilizations and, once found, indicate via an exclamation mark above their head (!) that there are sites worth pillaging.

Once notified, barbarians will begin producing units; although which units will be heavily dependent on the era. Typically you will see warriors and horseman charging around as raiding parties. These units are the ones that will actually pillage resources.[1]

 

As for other civilizations and city-states, it's a strategic decision between whether they want to bolster the unit's defenses or acquire the bonus(es) from pillaging a resource. The AI tends to bolster defense when an enemy unit is nearby. After all, there is more value keeping the unit alive then recovering whatever bonus is available from pillaging.[CITATION NEEDED]

 

REFERENCE:

  1. Civilopedia - §Barbarians