Many installation files are simply an installation program wrapped around a compressed file containing all the individual application files. Most anti-virus software can not only scan the installation file, but also each individual file compressed within the installtion program -- ...UNLESS, that feature is missing from your anti-virus software or the feature (to scan within compressed files) is disabled.
It sounds like the latter might be the case. If your anti-virus doesn't scan the contents of compressed files, it wouldn't "see" an infected file until it was de-compressed during installion.
To fix this, you need to enable scanning within compressed files, or if your anti-virus software doesn't support this feature (some free anti-virus softwares don't do this), replace it with one that does.