The current version is kind of funky, and I can't quite decipher what the intention is. A block shortly above sets up _${group}DIR_${file} to where we should be installing this specific file to, defaulting to ${group}DIR and expanding as needed.
This block ends up clobbering where we should be installing files to, in cases like this (contrived, similar to real use):
FILES+= foo bar FILESDIR_foo= /tmp FILESDIR_bar= /tmp .include <bsd.prog.mk>
An execution of this reveals that it figures out that foo is supposed to be in /tmp. but it screws up bar and this logic decides that it's supposed to go in FILESDIR instead of the clearly specified /tmp.