Hexwood, by Diana Wynne Jones
It's been a while since I read Hexwood! This is one of the most confusing books DWJ ever wrote, featuring an ordinary English village, an intergalactic empire with corrupt rulers, and a reality-manipulating, half-alive machine that is looking for revenge after a thousand years of imprisonment. We jump back and forth in time--only not--and people are not who they think they are. And there is a castle, and dragons.
I don't actually even know how to describe the plot, it's so complex. We start with Ann, whose parents run the greengrocer's shop. She goes into the wood, and it becomes much larger...and she meets a newly-resurrected wizard, Mordion (except that she saw him walk into the wood that morning), a little boy named Hume who keeps changing age, and their found robot, Yam.
DWJ gives us a whole set of villains: the five Reigners, who rule the entire interplanetary empire as a corrupt business. Each one is a portrait of the different ways in which people can go wrong. Four is vain and preys on women. Two sits back and lets others do his dirty work, after which he takes the profits. And One -- he's the ultimate Machiavellian sociopath who uses everything as a step up the ladder of power. He's the kind of person who takes his victims' desires for good and twists them, forcing them into doing the evil they tried to avoid. Mordion is his creation, his victim, and his executioner.
This is a book to work your way up to. Reading Hexwood as your first DWJ book would probably not be a great idea. I think it's usually classified as YA--I wouldn't give it to a kid. It is, by the way, dedicated to Neil Gaiman. And it's had a particularly awful selection of cover art, but I wouldn't want to try to design a cover for it either.
Oh, and King Arthur and Merlin show up, too! So this is an Arthurian spinoff, a bit. :)