What it does
Form 8802 is an application. You are asking the IRS to confirm that you were a US tax resident for a given year.
What comes back is Form 6166, a letter of US residency certification. That letter is the document a foreign tax authority wants to see.
Why an NRI in the US needs it
India will not apply a treaty rate to your Indian income on your say-so. It asks for a residency certificate issued by the government of the country you claim to be resident in.
For a US resident, that certificate is Form 6166, and Form 8802 is how you get it.
Timing is the practical problem
Processing is not immediate, and the certificate is issued for a specific year. Applying late, or for the wrong year, is the most common way this goes wrong.
The IRS charges a user fee for Form 8802 and publishes a processing time; both change, so we do not print them. Confirm the current figures with your US CPA or Enrolled Agent when you file, and build the processing time into your calendar — the certificate has to exist before the Indian payer can apply treaty rates.
What to do next
This page explains a rule. It does not work out what you owe, and it is not US tax advice. Take your fund statements to a US CPA or an Enrolled Agent, because the analysis runs per fund, per year.