I didn't know we had 25 000
Every count, knight or lord had to build himself a worthy residence.
The number sounds about right, almost every town has a castle or fortress. Some might only be a loose collection of stones these days...
Only few castles remained intact through wars and centuries.
In the Historism period nobles and investors started to restore ruins to their former glory to preserve the cultural heritage (for example Wartburg castle, only the remains of one tower were left in the 19th century)
This also included new building projects based on historical references.
Neuschwanenstein was the life project of the Bavarian king (who either commited suicide or was murdered, it remains a mystery). If he hadn't been a king he would have gone bankrupt, he even got declared legally incapable to save him (and Bavaria) from his debts.
He based Neuschwanenstein on Wartburg Castle.
So basically, we have to thank wasteful kings and historism for German fairytale castles