He takes advantage of the cloak of darkness to lure the giants (robbers, in other variants) to the castle to kill them. This type of narrative is classified as another tale type: AaTh 723*, "Hero Binds Midnight, Dawn, and Midday".
The story structure described involves a hero using darkness to lure enemies (giants or robbers) to the castle for their demise. This narrative type is categorized as AaTh 723*, "Hero Binds Midnight, Dawn, and Midday".