THE SHINING (1979) analysis by Rob Ager
Re: Danny
We know that the ghosts were visions/hallucinations. Every time Jack spoke with a ghost there was a mirror in front of him behind the "ghost" or the polished metal door in the pantry when he
spoke with Grady. Safe to assume a ghost could not unlock that door.
Danny knew that as long as Jack was alive there was a chance his mom would (once again) forgive him and let him out. She had a habit of always forgiving Jack even when he was abusing Danny.
So Danny unlocks the door and then goes and hides. He then lures Jack directly into the maze which he and his mom had learned by heart since they would always be checking it out. He also knew
his dad didn't know the maze at all since we never see Jack in it with them.
So he leads Jack to the center of the maze and then backtracks and covers his tracks knowing Jack will get lost giving Danny and his mom time to escape.