"hand something over to" or "hand over something to"?

Both structures are grammatical, and there is no difference in meaning between them.

When would one structure be recommended rather than the other?

If your noun phrase is short (like something or the prisoner), we would tend to put over after the noun phrase. If your noun phrase is longer (like someone such as a prisoner) we would tend to put over before the noun phrase.

One more comment: someone such as a prisoner isn't a long enough phrase for the position to make much difference; but for really long phrases, putting over before the phrase makes the sentence quite a bit easier to understand.