Some government officials came up with a plan to ensure that their tax revenue stays strong during the pandemic: Tax anyone who works for a business located in their area. But that’s not right. It’s not how income taxes should work. And it’s unconstitutional.

Which is why it’s good that New Hampshire has challenged Massachusetts’ attempt to tax the income of New Hampshire residents who work remotely for companies based in the Bay State.

Most states levy an income tax and another 17 states allow local governments to impose one. Government costs money, and some people believe this is the fairest way to get it. Their thinking: Live somewhere else if you don’t want to pay.

When the pandemic came around, many commuters stopped traveling to their employer’s city or state. Seeing this, some treasurers thought they’d tax remote workers if they worked for a business located in their area. Why should cities and states take a hit just because more people were working from home? The business was still there within their tax borders, right?

That’s not how income taxes are supposed to work. Governments are authorized to tax the incomes earned within their borders, and people who aren’t earning income there shouldn’t be subject to the tax.

It’s important to keep the reach of tax jurisdictions from growing out of control. Economic activity is intertwined across political jurisdictions. Iron ore mined in Minnesota become trucks made in Michigan. People earn income along the way, and if governments are going to tax income, it ought to be based on where it is earned. Put another way, Minnesota shouldn’t start taxing the truck assemblers in Michigan because they work with Minnesota ore. Things are complicated enough without expanding the definition of where income is earned.

The definition is well-established: Previous court rulings limit income taxes to income earned by residents and for work performed there by nonresidents.

In the words of one 1992 ruling, the U.S. Constitution’s commerce clause and the due process clause prevent the state from taxing “value earned outside its borders.” Commuters living in the same state but not the same city as their employer may find it more difficult to challenge city income taxes. But the basic principle still works the same: If you’re not earning income in the city, the city shouldn’t be taxing your income.

Which is why it was good of New Hampshire to sue Massachusetts when the latter started levying taxes on people who weren’t working there. Massachusetts shouldn’t levy these taxes, and New Hampshire residents ought to get any funds that were withheld refunded.

There is another aspect of fairness here as well. Officials accept the risks that their revenue is going to be volatile when they elect to tax income. It goes up in good times and goes down in bad times. And while officials shouldn’t be blamed for failing to prepare for a switch to remote work brought about by a pandemic, they still need to accept the rules of the policy. City income taxes allow them to tax the income earned within the city borders. If people don’t earn income in the city, then the city shouldn’t tax their income.

These governments also shouldn’t be starved for cash right now. Yes, a drop in the number of commuters can depress one of their revenue sources. Cities, even those with an income tax, rely primarily on property tax revenue, and the real estate market has been surprisingly robust through the pandemic.

In addition, the federal government has already provided multiple bailouts for states and local governments and given them extra money for COVID-related needs. The latest round includes $350 billion in general support for state and local governments. The local share is more than three times the amount that local governments collect in income taxes. States collect more than local governments in income taxes, but they’re also more protected from the increase in remote work, and their tax receipts have been robust. In other words, local governments shouldn’t be so desperate for cash as to try unconstitutional interpretations of tax policy.

Taxpayers ought to push back and challenge the governments doing the collecting. Some are already. But government officials shouldn’t have tried in the first place.