At a low level, everything on the disk is a file. So a folder is a special file that contains directory information pointing to more files.
The application is told that the file should be opened - and it's up to the program to determine what type of file was passed and decide whether to recursively handle that file by reading the files contained in that folder or take some other action.
Similarly, you can select many items in Finder and drop them on an icon and the same sort of file open event is posted to the application so that it can process the files and do what needs to be done.