Can we use two pronouns side by side?
I don’t know why you think that that example has any “grammatical” error in it. As far as English grammar goes, it is impeccable. It’s not that it’s ungrammatical so much as that it may be ungainly. It’s like with saying it’s something that you do do, or there’s ours and there’s theirs, or that you like like things more than you like unlike ones, or that he asked me to tomorrow, or he said yes yesterday. These things happen, and sometimes they’re completely unavoidable.
There is nothing fundamentally or theoretically “wrong” with having the same “word” twice in a row in English. These things inevitably happen, both with duplicate words and with sequences of homophones.
However, these repetitions can sometimes become awkward either to read, to speak, or both. This is one of those cases where phrasally it is hard to enunciate it both clearly and naturally, for reasons more complex than are worth delving into too deeply.
If it feels awkward to you, then by all means rephrase it. But this is not a matter of grammar or rules, just of clarity and convenience.
As tchrist said, there is nothing wrong with this, it is just clumsy. The sentence would be better written as
Jane had taken the book from Ann five months ago, and hence felt the need to return it as soon as possible.
or
Jane had taken the book from Ann five months ago, and hence felt the need to return it to her as soon as possible.
If you must use her twice, separate them:
Jane had taken the book from Ann five months ago, and hence felt the need to return her book to her as soon as possible.
There's nothing wrong with that. Imagine this sentence:
Jane asked Tom for a book, which was currently in the possession of John, so Jane asked John to give him her book.
This sentence doesn't sound nearly so bad because you are using two different pronouns, but if you accept this sentence, your sentence is just as grammatically correct.
Of course, if you still feel this doesn't sound good, you could always rephrase it as:
Jane had taken the book from Ann five months ago, and hence felt the need to return her book to her as soon as possible.