"We sleep in the castle."
Translation:Vi sover på slottet.
Being a native speaker of Danish I can tell that (as far as I know) there is no rule when you use "på" and "i". You say "på badeværelset" (in the bathroom) but also "i soveværelset" (in the sleeping room). Both words end with some form of "værelse" (room) so I guess it is a matter of remembering when to use what.
The public building rule seems ok as you say "på rådhuset" (in the city hall), "på sygehuset/hospitalet" (in the hospital), "på (tog)stationen" (in the train station), "på skolen" ((in the school). N.B.: "på skolen" is only used when you say that you psysically are INSIDE the school - if you want to say you did something in school you say "i skolen").
The only public place I can think of that uses "i" is "supermarked"-->"i supermarkedet".
Hope this helps