This medal is from the city of Hamburg. It is in relation to the Great Fire that occurred there on 5th through 8th May 1842. Medals were cast from bronze that came from church bells from 3 churches that were destroyed in the fire. Money raised from sale of the medals was used in helping toward the recovery of the city. From what I can find, there are several designs, all quite different from each other.
The castle has been a part of the coat of arms of the city dating back approximately 800 years, and often appears on coins of Hamburg.