"Castle" churches were very common adjuncts to royal quarters, and often re-purposed over the years.
A famous example: The Basilica d'San Marco (St. Mark's Cathedral) in Venice, adjacent to the Doges Palace, was for many centuries the Chapel of the Palace (rather more ornate than many...). The Chapel became the Basilica, or cathedral, of the Archdiocese at the command of Napoleon Empire overlords in 1807, placing the function there to be in the center of and under the thumb of government in the former Republic. Why? Check out Napoleon's history of "revisions" to the church and placing of its authority under his crown (self-coronated fellow). The church of San Pietro d'Castello on the east-side island of Olivolo (now Isola San Pietro) had been the seat of the Archdiocese and then the Basilica of the Patriarch of Venice - as far from the seat of secular power as could be in the island city.
All still standing, after numerous remodels/restorations.
By the way, the Doge was elected, not royalty, but "palace" sounds important.