Castles have high towers for them to roost in and scout, lots of surrounding land for food and water. Obviously the biggest problem would be getting the people living in them to either clear off, or make an agreement with. I need help thinking circumstances or either pressures that would lead them to abandon their original habitats for castles.
Large predatory animals such as griffons would likely naturally disperse to any suitable habitat, mostly as younger individuals without a territory leave their parent's nest and set out on their own. This is how, for example, black bears, mountain lions, and coyotes have spread across much of North America after being removed from much of their ancestral range. Young carnivores will often establish themselves in any unoccupied area, but the ones who establish themselves in poor-quality habitats either die or leave for better pastures. All you need to do is justify why castles would be a good enough habitat for a young griffon to establish a territory in.
I think the real critical question is "How do you entice humans to build nests for griffins to live in?" Large, aggressive apex predators don't generally get along well with humans.
If, on the other hand, you had a pacifistic (possibly even vegetarian) intelligent species that needed protection (imagine halflings), they could raise sheep for the griffins to eat, build tall closed-off towers for the griffons to live in, and in exchange the griffins don't recognize pacifists as either food nor threats. The griffons do, however, aggressively drive off anything else (like someone attacking the pacifist village).The griffons might even be friendly towards the villagers, who could groom the griffons, delouse, and bind wounds (in a manner similar to certain birds that pick food out of the mouths of other animals like dentists). Villages large enough to support many towers and sheep could support many griffons (assuming the griffons are willing to live in close proximity).
Any abandoned castles or tall buildings of other species would logically be places griffons would recognize as homes. If there were enough villages of pacifists, griffons would obviously prefer to live in places where the locals pamper them. If the relationship continued long enough, the eggs of griffons who die could be raised by the pacifists and the griffins might gradually become increasingly domesticated.
No self-respecting castle or palace didn't have one or two griffons guarding the gates. They have incredible patience and can sit motionless for long periods of time like a cat waiting at a mousehole. They also quickly learn to distinguish friend from foe just as guard dogs do.
Sadly, they have now gone extinct but the tradition is remembered by erecting statues where the real animals used to carry out their duties.
They were well-fed and although never fully domesticated, their handlers were skilled in directing them against intruders.
Pretty self-explanatory. A high perch that overlooks lots of fertile lowlands is pretty desirable for both humans and griffins, so it's only a matter of time before castle(s) appear within or near the edges of griffin territory. The question then is how the humans would complete their castle before being set upon by griffins, which you can rationalise with an instinctive selection for heights. The initial structures would be ignored as long as they are relatively low compared to natural features like trees and hills; the nearer the castle is to completion the more likely the griffin is to take notice.
Since griffins like that kind of roosts, building castles near them that would be like leaving empty cardboard boxes near stray cats. Boxes full of food, since griffins are presumably carnivorous and thus would happily eat both people and their livestock.