Speculation
The house-elf binding is older than the wizards who use it
House-elves may serve wizarding families because of ancient magical contracts made centuries ago, not because wizards invented their servitude. The binding could predate modern wizarding society entirely.
Every house-elf we meet treats their bond as something fundamental to their nature, not a spell some wizard cast on their ancestors. The magic runs too deep for that. When an elf receives clothes, the binding breaks instantly without any counter-curse needed, suggesting the original contract included its own escape clause. The founding-era wizards already had house-elves in their service, meaning the arrangement existed before Hogwarts was built. Perhaps the elves once made a collective bargain during a time of crisis, trading their labor for magical protection or sustenance their species desperately needed.
The self-punishment behavior could be the contract enforcing itself, not cruelty wizards designed. If ancient elves agreed to serve faithfully in exchange for something vital, the magic might punish those who break their own species' oath. Modern wizards inherited this system without understanding its origins, which explains why even kind masters never question it. The binding persists because both species forget it began as negotiation, not conquest. The clothes-freedom clause suggests the original elves wanted an exit available, though they hoped their descendants would never need it.
The other side
Wizards demonstrably create powerful compulsion magic, so assuming they couldn't have enslaved house-elves seems naive. The immediate self-punishment when elves disobey their masters looks exactly like a control spell designed to maintain dominance. If this were truly an ancient mutual agreement, some wizarding family would have preserved the historical record to justify their use of elf labor, yet no one ever mentions such documentation.