And more specifically for the second part of OP's question:
but in what sense is the hide in hiding contributing the meaning of the idiom?
Here, "hiding" is a noun used as a colloquial near synonym for "a beating". According to the OED, it goes back to activities involved in tanning a hide, related to the verb hide2, "2. To beat the hide or skin of; to flog, thrash". For the noun, OED gives this example from 1822 (not the oldest) for the equation with "a thrashing":
Giving him a severe beating, or, what was called, a ‘hideing’.
Thomas Bewick, Select fables..., 118.
Its use in the phrase a hiding to nothing means to get no benefit from this painful activity, as described already in the accepted answer.