We both agree that castles were never designed to defend against dragons in the real world. That was in fact my very point.The idea that castles should be "dragon proof" is, IMO, a flawed one. Castles weren't designed for that so it's no surprise that they aren't as effective against dragons.

We disagree that the idea that castles should be "dragon proof" is flawed. Tell that to the lord who wants to protect his daughter and the local population that has retreated into his castle for protection against a raiding dragon! I think it might be a very legitimate concern were a dragon to attack your kingdom.
One may argue that dragon raids are rare occurrences, or that should it happen nothing can be done about it. It strikes me as somewhat cavalier to suggest that a frightened populace should just grin and bear it. It need only take a single dragon attack to strike such fear in the heart of a lord that he becomes driven to build a fortress that would withstand such attacks in future. Regardless of actual frequency of attacks, I can't imagine that some castle-builders would not be motivated to build dragon proof castles out of fear, pride, sense of duty or just for bragging rights.
Anyway, Dragon attacks are quite plentiful in fantasy literature and movies. I don't think it's unreasonable to assume a typical fantasy world where dragon attacks are common, or at least frequent enough to be an abiding concern for castle builders. What's frequent? Once a season? Whenever the dragon wakes up from hibernation? Once a decade? Even if it's just once a generation, or once every century! Wouldn't that be enough to spur intensive fortification efforts?
Lets also not forget that D&D dragons are motivated to collect hoards; and castles are where the lords and heroes usually keep their treasure. So the very act of building a castle might attract dragons like putting up a flashing neon sign that says "OPEN HERE TO REMOVE TREASURE"!
That said, your point is very well taken that the best defense may be a good offense and I agree with you that a castle may be well served by garrisoning as many dragon-fighters and weapons that it can muster to "defend" it by taking the fight out to the dragon.
As such, castle architects might focus their efforts on constructing barracks, store rooms for food and weapons, stables and aviaries to house mounts, turrets and lunettes to serve as launch and landing platforms, watch towers to spot foes and bell towers to alert troops and warn civillians to take cover, etc. All those things sound like sensible architectural adaptations to threats unique to a fantasy world.
But I don't think that castle architects would just give up on the idea of making their fortresses impregnable to dragons (and gryphon riders and arch-mages). A castle has got to be more than just a dormitory for dragon fighters. I think they would still try very hard to craft what protections they could, and I think a little ingenuity by motivated stakeholders would produce some interesting solutions.
While I will be the first to admit that I learned almost everything I know about castles from reading David Macaulay's "Castle", and from 30+ years of reading fantasy and gaming sourcebooks, not to mention movies like The Two Towers, Prince Caspian, Troy and Return of the King. My template for castles may well be idealized and unrealistic, no doubt! Although, I have visited a few real-life castles as a tourist, including the Chateau de Chillon he depicted (which, please note, does have 3 inner courtyards). But please note that I never said that "all" castles possess crenelations and large baileys; I merely pointed out that some castles definitely do have such features and those features might be less useful in facing off against fantastic foes.
But Celebrim is perhaps right that I have skewed notions about what castles were "really" like. And I have very much enjoyed reading his comments; he has raised a lot of interesting points and taught me a variety of useful information.
I do want to say that my answer to the question posed as the title of this thread was never meant to imply that my answer was "no". It is not my belief at all that castles make no sense in a world of dragons and spells. I just think they would look somewhat different than those castles depicted in the romanticized cover art of fantasy novels, matte paintings in movies, and comic book illustrations.
My goal in asking the question was mainly to provoke some deep thought about whether fortifications that look more like Moorish, Slavic, or Japanese castles would be more suited to the fantastic threats such peoples would face. Or maybe something entirely new and different. I am now particularly intrigued with the idea of star-forts that evolved in more recent times to deal with the advent of cannons, guns and explosives. Or perhaps Celebrim is correct that medieval style castles (with minimal modifications) would be able defenses for fantastical threats. Whatever the answers, I think the question is at least worth pondering and I think it doesn't hurt to challenge assumptions and try to think outside the box.
I will not, however, admit that my original question was "flawed" in that it has provoked 14 pages (and counting) of interesting and creative discussion, and fostered learning about castle construction techniques, military strategy, logistics, and architectural history. In that sense the question has achieved exactly what I set out to do and I would call that successful by any account.
