system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Why is diplomatic immunity a thing and how did it come about?
gpt
Diplomats are people who travel to other countries and act as representatives of those countries interests. This was very important before the days of telephone or the internet where communication over great distances took a very long time. Messages were slow to exchange and relationships hard to build. Instead of trying to do it from afar a special professional was chosen to build that relationship and look after foreign interests under the direction of their home country.

In order for that to happen there needs to be an agreement that the diplomat won't be legally hassled by the host country. Tossing the diplomat into prison or torturing them until they agree with whatever you want isn't acceptable to the country they represent. This means that minor transgressions are generally overlooked in the interest of diplomacy; if the diplomat parks in the wrong place and would otherwise get a ticket it is just ignored.

Basically the diplomat is "immune" to the normal course of legal process. If the diplomat does something the host country finds unacceptable then the host country will simply kick them out of the country, and potentially the relationship with the country they represent could be damaged. Or the immunity can be revoked with the agreement of the diplomat's home country and the diplomat prosecuted as normal. Broadly though it is a protection against trumped up charges being used as a tool of diplomatic leverage.