Short answer: absolutely.
Long answer:
Given that castles are, by their nature, fortifications, you would be hard pressed to find a more defensible building in the world (other than in an operational military base, at least). Using a castle in a zombie apocalypse scenario would have several pros and cons, as expressed below.
Pros:
A castle is made entirely of strong walls, which are designed to deter entry and keep enemies out. Zombies, being of minimum intelligence, will be unable to penetrate strong walls so long as they are in good condition.
Almost every medieval style castle was built with active defense in mind. This means that man castles have ports to fire arrow from. Also, there tend to be locations to drop hot oil or other substances onto intruders. These ports and holes can be modified or used outright for rifle-wielding people, and if they are close enough to the ground, pole-arms and bayonets are also an option.
Castles tend to have high points, which are made for increased vantage for intelligence gathering. For the most part, any intruder is visible for miles, and slow moving zombies could be watched for days as they move either towards away from your fortification.
Castles tend to have multiple layers of defenses. This is known as defense-in-depth, and means that even if zombies make it past one layer, you have another ring of walls to fall back behind and continue defending with as of yet unbroken defenses.
Cons:
Castles are large. Large buildings require either highly mobile or a lot of defenders to properly defend from active threats. If humans got involved, you'd be hard pressed to keep the whole thing defended.
Castles tend to be somewhat complex. If there are weak points anywhere that a zombie could get through, several of them could be in your castle before you even know it.
Many castles are not well ventilated or very modern in terms of human safety. You run the risk of such things are mold and other growth making the humans that live there sick and less effective as defenders.
Most castles are old, and lack certain design features like power distribution and plumbing. Most of those services won't really work in the apocalypse scenario anyway, but having them just in case sure would be nice.
Conclusion:
I'd say, assuming you had no better options, a castle would be a wonderful place to set up for a long defense against zombies. Perhaps the closest modern analogue would be jails, although jails are mostly designed to keep people in, not always out.
There is a series of zombies that uses a jail as its location for several episodes (The Walking Dead, seasons 3 and 4) and this series manages to outline some great pros and cons to the hard-building approach to survival.