Your H1b status is tied to your presence in USA. Your payroll needs to run in USA only for the duration while you are in USA on H1b.
During my cool-off period ( 1 year outside of USA after 6 years in USA and no PERM approved), I had option to work from Canada (on Work Permit ) and from India. I had asked HR to run payroll from USA while I was in India ( would have been cool to get US salary while working from India) and my request was denied on compliance issues.
I know several India based IT companies rotate their H1b Employees in and out of USA. While these employees are in USA, their payroll runs in USA while they are in India their payroll runs in India. Also, few friends of mine, working for Desi consultancies, were asked to search from project from outside of USA as Desi consultancies were unable to run payroll for consultants on bench. No projects, no work and hence no payroll. While these H1b employees were outside of USA, their payroll was not ran anywhere and few of those returned back to USA after finding projects.
It's my understanding that for short term ( for ex - vacations or emergencies) companies ignore this compliance requirement but for long term they try to find work around ( for ex - moving employee to local payroll or letting employee work as contractor through a staffing company that has branches in USA and local country)
As per IRS, Non-resident aliens need not pay US taxes for work performed outside USA.
https://www.irs.gov/individuals/international-taxpayers/persons-employed-abroad-by-a-us-person
"Nonresident Aliens: As a general rule, wages earned by nonresident aliens for services performed outside of the United States for any employer are foreign source income and therefore are not subject to reporting and withholding of U.S. federal income tax."
Here are few internet links for discussion on same issue:
https://www.quora.com/Can-a-foreigner-on-H1B-work-remotely-from-outside-the-US-What-are-the-limits-on-length-What-are-the-implications-for-H1B-visa-and-US-payroll
https://www.quora.com/Can-I-receive-US-based-income-while-working-remotely-for-a-US-company-without-a-work-visa
https://www.trackitt.com/usa-discussion-forums/i140/1172145323/us-payroll-while-in-india-for-i-140
Your company had to do that because they need to officially wean you off from US employment because your work permit ended. It should be your company's internal compliance, and nothing to do with laws. If you leave US on time, then how they continue to pay doesn't matter at all. Actually none of those Quora links say that you are not supposed to do this... the overall advice is to look in to the immigration laws of the country where you are physically working and you are good to go. Check this immigration attorney's response in your first link..
//As long as you are working outside the US, you are not subject to US immigration laws. So you will not be limited in your ability to work for this company while you are outside of the US, even though it is a US company. Since you are looking to work outside of your home country, the work/immigration laws you need to be concerned about are the laws of that country.
Also, a person can only be in H1b status while he or she is physically present in the US. Even if you currently have H1b status and have not used up all your H1b time, you are not in H1b status when you travel abroad. This is true even if you continue working remotely for the US company while you are abroad. The time you spend working abroad does not count toward your 6 year maximum H1b limit. If you keep documentation of time spent outside of the US, the employer can use this to reclaim this time and extend your H1b.//
Indian companies switch people payrolls because they cannot afford to pay people in USD while working in India. Clients won't agree to bill someone working from India for an onshore rate. It has nothing to do with laws or compliance. And regarding desi consultancies.. why would they pay someone without project, that too when in India.They just cannot be without paying while in US as someone is employed by them, so they ask people to leave to India. It has nothing to do with legal or compliance reasons.. it is purely financial reasons. In case of FTEs, they still actively work for a company and hence pay is justified, and it doesn't matter how they pay.
Most companies will switch payroll to geography of work if there is an option to do so purely because of cost effectiveness, operational effectiveness, and internal policy restrictions, but they are not obliged to do so by law at all. The clauses mentioned in I9 is applicable only when someone is physically work in US, so one is good there too.
As long as you file appropriately with IRS, it should be fine. I think if you are considered as resident only if you spend 183 days in US. Else you can file as non resident and get whatever was deducted as taxes back. Someone with h1b living in Canada will definitely spend some days in US. If you don't pay tax to US, you will end up paying it in Canada. It is a complicated topic anyways, but absolutely doable, but people have been there, done that.