A GSTIN is not a random number: characters 3–12 of every genuine GSTIN are the registrant's own 10-character PAN. So on an honest invoice, the PAN printed in the header and the PAN buried inside the GSTIN are the same ten characters. When they differ, the two identifiers belong to different entities — the invoice is carrying someone else's GSTIN, a fabricated PAN, or both.
That is exactly how a common vendor-invoice fraud works: a fraudster copies a real, active GSTIN from another business (so a registry lookup "passes") and pairs it with their own bank account and PAN. The consistency check above catches that pairing in one second, before the payment leaves your account.