Get your taxes done using TurboTax

If you are a US resident for 2021, but for no part of 2022, then your US residency ends on the last day in 2021 that you are physically present in the US. 

 

Look under "last year of residency" in publication 519.

https://www.irs.gov/publications/p519

 

That makes you a dual-status alien for 2021.  You file as a resident for your residency period and pay tax on all your world-wide income, and you file as a non-resident for the period of time after you leave, and only pay tax on US-source income.  Your income is NOT US-source income if you are physically living and working overseas when the money is paid, even if the employer is based in the US.  

 

Based on your question, and as long as you will not be a US resident alien in 2022, then your income after you return to Pakistan will not be subject to US taxation.  I can't tell you about Pakistani taxes.

 

If you are a resident of the US at any time in 2022, you will be considered a full-year resident for 2021 and you will owe US income tax on all your world-wide income, including income paid to you while living and working in Pakistan.  I can't tell you about Pakistani taxes, but if you do pay taxes in Pakistan on the same income, you can claim an offsetting deduction or credit on your US tax return.