Nietzsche says in the Genealogy of Morals in dispersed sections in the book:
I have already let it out: in the contractual relationship
between creditor and debtor, which is as old as the very conception of a ‘legal subject’ and itself refers back to the basic forms of buying, selling,
bartering, trade and traffic.
Precisely here, promises are made; precisely here, the person making the promise has to have a memory made for him: precisely here, we may suppose, is a repository of hard, cruel, painful things. The debtor, in order to inspire confidence that the promise of repayment will be honoured, in order to give a guarantee of the solemnity and sanctity of his promise, and in order to etch the duty and obligation of repayment into his conscience, pawns something to the creditor by means of the contract in case he does
not pay, something that he still ‘possesses’ and controls...
Punishment as a means of rendering harmless, of preventing further harm. Punishment as payment of a debt to the creditor in any form (even one of emotional compensation).
One could compare and contrast Nietzsche's and Marx's views on credit. (See especially section 5, second essay, in Genealogy of Morals).
Also, Nietzsche was niether a materialist nor an "immaterialist" because he despised all metaphysics. He saw Metaphysics as that very culprit of making the distinctiom between "appearance" and "reality" which ends up destroying both worlds of metaphysics because philosophers can't decide if the transcendent ("reality") world is real or if the phenomenal (appearances) world is real. To get a glimpse of how Nietzsche solves this problem you're gonna have to read Thus Spoke Zarathustra and Ecce Homo. In Ecce Homo he says: "Zarathustra was the first to see in the struggle of good and evil the true wheel in the working of things — the translation of morality into the metaphysical, as force, first cause, end-in-itself, is his work."
Nietzsche saw morality and metaphysics as interconnected, so he uses Zarathustra to go beyond morality and thus go beyond metaphysics. You're gonna have to do a close reading on Thus Spoke Zarathustra on how he does go beyond metaphysics!
(You also have to remember materialism and metaphysics are predominantly philosophy of science terms and Nietzsche certainly was not a philosopher of science, so its best not to read him through that lens...)