As part of the plugin installation (loading) the script is processed and thus any global declarations are processed. Then it calls OnPluginInstall, if present. However for that to work the function OnPluginInstall must already exist, so therefore executing all global declarations is the very first thing that happens.
See for yourself by putting a line like this at the bottom of the script part in a plugin:
Note ("Script reloading: ", os.date ("%c"))
When you see that, the plugin is loading its script. Note that you may not see that at world startup because plugins load before the main output window is initialized, and thus the message may disappear. You could try appending it to a notepad instead, which will always work.