Bruce and Sabrina Hecker, both schoolteachers, thought they did everything right when they put a couple of rooms up for short-term rentals in their narrow but ornate townhouse in a historic district in Washington Heights.

But in April, a team of inspectors from the Mayor’s Office of Special Enforcement swept in and determined that their short-term stays were completely illegal. They were issued four separate summonses with potential penalties of more than $8,000.

One...