As it turns out, many companies do exactly this. And (apparently) their developers decided it was a fair deal. But if you don't like that deal, that's an entirely reasonable choice. In that case, just don't work for such a company, even if they offer better salaries.
It would be unfair to say "don't take the job if you don't like the deal" if there weren't other options, but the fact is that there are lots of other options. There are plenty of software jobs that don't include such clauses, especially in the non-profit and academic sector.