"By" is a preposition in English that is frequently used to replace the instrumental case in Old English.
instrumental case: this case is expressed by inflection in Old English, Sanskrit, Russian, etc., and in English with the prepositions by or with (Ex.: OE ðȳ spere, “by the spear, with the spear”) Collins English Dictionary
With the collapse of the declension system in English, beginning a thousand years ago, prepositions were required to express the function of a noun or pronoun.
It is the mechanism by which hospitals are reimbursed by Medicare.
Hospitals are reimbursed . The means of this reimbursement is the mechanism; "which" refers to the mechanism.
"Which" (mechanism) can be thought of as the instrument of reimbursement .
This sentence could be writen differently:
By this mechanism hospitals are reimbursed by Medicare.
"Which" is gone.
So long as "which" is present, referring to "mechanism". the "by" is required to indicate the instrumental nature of "mechanism".
Without the "by":
It is the mechanism which hospitals are reimbursed by Medicare.
The "by" might be understood, but it might not . The second "by" (by Medicare) is a separate instrumental unrelated to "by which".