What established the diplomatic immunity? There isn’t a constitutional requirement that there be such a thing. It was an act of Congress that did so.
Of course in today’s Calvinball feelgood regime the prevalence of sheer sense is now in danger.
I believe that exitsed as a matter of international law, independent of statute. Not that a statute doesn't or couldn't exist, just that I believe a court would entertain the defense of diplomatic immunity, whether or not there was a statute on point. surely there are cases where the question of "diplomat or not" is tough to answer, and statutes might clarify that point.
It's a product of treaty, in this case the Vienna Convention on Diplomatic Relations from 1961.
Treaty is the same basis for excluding Indians - our dealings with them them were goverened by treaty.