One and the same person is serving both as object of the preposition to and as subject of the verb gave. Thus both subjective and objective pronoun forms come into play. It is part of the virtue or function of the relative pronoun, in this case who, to mediate such a shift in case. That frees the third-person masculine singular personal pronoun to assume the case appropriate to its role as object of the preposition to, which is him. The need for a subjective-case pronoun to be subject of the verb gave is filled by the relative who, which does here manifest its subjective-case form, who, as opposed to whom. (The case of the relative generally accords with its syntactic role within the relative clause, which here is as the subject of the clause.) Thus for formal edited written English the preferred form of your sentence would be
Return it to him who gave it to you.
While the person to whom “it” is to be returned may be considered the indirect object of the verb return (“it” being the direct object), for purposes of determining pronoun case it is better considered as object of the preposition to, since Modern English has no separate dative case for indirect objects.