From the Super Mario Wiki
The resident demon is found in the Ghost Train Ride, a mini-quest in the area Creepy Castle. After Donkey Kong uses his Gorilla Grab on several levers in the Skull Cave, he gains access to the Ghost Train Ride.
The resident demon attempts to attack Donkey with its disembodied claws, each hit from it causes Donkey Kong to lose some of the coins he has collected. It cannot be hurt in any way; Donkey Kong must avoid its slashes and punches by jumping from rail track to rail track. When Donkey Kong reaches a section of the track with three parallel rails, the demon resident will fire several flaming skulls, which explode similarly to TNT Barrels and cause Donkey to lose three coins if he is hit.