To pass through the land of Nightmares, ruled over by demons and where mortals such as Tripitaka would be killed, enslaved or eaten, Monkey disguises Tripitaka - why exactly he has to cross-dress Tripitaka is not made clear, save to provide the jokes when Pigsy starts lusting after the master - and gives him enough magical power to temporarily pretend to be a spirit.
This isn't necessary in the end, because Tripitaka is given a free pass when he is the 500,000th visitor to the land of Nightmares. This must have been something of a marketing gimmick in the '70s and early '80s, and I vaguely recall this being used as a plot-point in other programmes of the time. These days you only ever seem to see it in the form of dodgy adverts in certain parts of the internet - you are the 10,000,000th visitor to this website, click here!
Monkey gains admittance to the land by showing the demons an impressive trick - flying on his cloud he spells out "Monkey Magic" and then causes a destructive storm. Clearly demons are impressed by that kind of thing. Pigsy's magic trick is less impressive, and Sandy's less impressive still, and they are accorded less status in the land as a result.
The guest of the demon king, Tripitaka eventually gives himself away when he doesn't want to watch two men fight to the death for his entertainment. The demons then round up Monkey, Pigsy and Sandy as well, and take them all off to be crucified.
Tripitaka is the one to save the day - rather than Monkey, for a change - when he recognises that this is a magic land that runs on the rules of dreams and nightmares. His prayers cause a solar eclipse to occur, which terrifies all the demons and they beg him to bring the sun back and they acknowledge Tripitaka as their master and allow the pilgrims to go free.
This is a solid episode and one I would recommend, it showcases the silliness and spectacle of Monkey in equal measure.