This is some really old stuff! A castle was built by the Danish king in 1268 and its purpose was to protect the border between Denmark and the Duchy of Schleswig (we since pushed the border a bit further south). It has been rebuilt loads of times and buildings have been added, but the version we see today is (re)built by King Frederik IX in 1720. It did though burn down in 1808 and was nothing but a ruin for more than 100 years, until it is rebuilt yet again. However, the ruins are still visible between the more recent walls.
Today, the castle is a museum with activities for large and small and houses various exhibitions every year.