Some of them just potter around. Like the library-ghost. She'll hand you a book from time to time. Some are a little more aggressive in the way they get attention, but they can't hurt you. Or they haven't to my knowledge.
Mostly they seem to keep the place in order. Keep us in order if we stray from our assigned rooms or attempt to get into places we're not allowed.