Any work published before 1928 is in the “public domain”.
Anybody can use the characters, retell the story, etc etc. if a work is in the public domain. Shakespeare, Jane Austen, and James Fenimore Cooper fall into this category. So I am completely within the law by retelling Cooper’s The Pioneers and using some of his characters. There are hundreds and hundreds of books in the public domain that you can get for free over the web. A good list is maintained here.
Works that are still in copyright: no, you can’t just borrow the characters. You can’t write a novel about Captain Kirk and Spock on the Enterprise unless you first get written permission from the owner of that copyright — I think that would be Paramount, and I doubt they’d be receptive. So technically fan fiction is illegal, though I don’t think anybody has ever sued over it.
I used Diana Gabaldon’s characters with her permission, both oral and written. Anybody else who wanted to publish a novel using my characters or hers would have to ask first — with the exception, of course, of those characters already in the public domain. So you wouldn’t have to ask me to have Hawkeye tramping through your novel, but you would have to ask me if he had a son called Nathaniel with a wife Elizabeth Middleton who lived in Paradise on the Sacandaga.