The version of Monkey that I have read is the Penguin Classics version, which spends about half of its time leading up the beginning of the journey to the west, which means it doesn't have as much space as you might think devoted to the various escapades along the way.
But one of the stories that is told is the one that is the subject of this episode. The king of the land of Cock Crow has been murdered by a magician that was his friend, and who has now taken his appearance to replace him as both king and husband to the real king's wife.
The dead king appears as a ghost to Tripitaka and, after the priest recounts his dream to the others, and shows them the king's jade seal as proof it was not just a dream, Monkey gets straight on it.
Monkey goes to the king's son and partially convinces him of what has happened to his real father with the jade seal, but the prince goes to his mother and asks her if the king has acted strangely recently - which he has.
Final proof is obtained when Pigsy is sent down the well (hence the story title) where the murderer dumped the real king's body to fetch it.
The most amusing part of the episode is when Monkey and Pigsy trick each other - Monkey fools Pigsy into doing a silly dance in front of Tripitaka, who is not amused. Pigsy gets his own back by telling Tripitaka that Monkey knows how to bring the dead king back to life.
This backfires when it turns out Monkey does, in fact, know how to do just that, and so he goes off to heaven to obtain some of Lao Tzu's elixir of immortality. The patriarch of the Tao, one of the most revered of philosophers, is portrayed as a bit of a fool, who Monkey easily outwits to acquire the necessary elixir.
With the king returned to life and his son the prince on-side as well, they accompany the pilgrims to visit the false king, who is exposed as an impostor.
After a brief attempt at disguising himself as Tripitaka - foiled when, to Monkey's discomfort, the real Tripitaka is the only one who knows the headache sutra - the villain is at bay and then the queen turns out, suddenly and randomly, to be in love with the impostor instead of the real king, before being killed by her son accidentally.
This is a change from the ending to the story in the book, where the magician is revealed to be a heavenly lion, acting under orders to usurp the kingdom for three years as part of the king's karma. Then the land and the king are restored and there is no tragic aspect to the tale's ending.
It only goes to show that Hamlet's father would have done a lot better if he had enlisted the help of the Great Sage Equal of Heaven, instead of his son.