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 hero uses the cloak of night to entice the giants (or robbers) to the castle for their demise. This story structure falls under the category of AaTh 723*, "Hero Binds Midnight, Dawn, and Midday".