Tenants sign agreements not to rent out their units all the time. Home owner's associations often have rules against short-term rentals as well.
If you don't like the idea of short-term rentals in your neighborhood or building, choose one protected by one of these types of contracts. In fact, they're so common, you probably already have such protections, even if you don't know it.
The government making something illegal really should be the last resort for societal problems. I'm not convinced short-term rentals are really so harmful as to meet that threshold.