This quote, uttered by Digory, comes early on in the eighth chapter of The Magician’s Nephew, after he realizes they have brought his Uncle Andrew along with them when they jumped between worlds. He and Polly have just gone through a bit of an ordeal, with the Witch causing a scene in this world, riding the horse Strawberry through the streets brandishing an iron bar and beating down anyone in her path. Digory managed to get a grip on the Witch’s heel, and Polly put on the yellow ring, causing all four of them, as well as anyone who happened to be touching them at the time – Uncle Andrew included – to be transported.
The exclamation “My hat, what a picnic” is meant to be sarcastic. “My hat” is a rather old-fashioned, primarily British phrase akin to “my God” or “my goodness,” and “what a picnic” in this instance is employed to mean the exact opposite (“sorting through this mess will not be fun at all!”), implying that they have found themselves in a pickle indeed by bringing Digory’s uncle with them. Compare this with Polly’s exclamation a bit later: “This will be a pretty kettle of fish!” meaning they have quite the awkward situation to sort out.
Essentially, this phrase sums up the frustration felt by Digory and Polly upon realizing they have brought unintended people into this new world, and their budding anxiety over how on earth to go about correcting the situation. Dictionary definitions for “my hat” and “kettle of fish” can be found at the links below.