From Yahoo answers:
Diplomatic immunity is a form of legal immunity and a policy held between governments, which ensures that diplomats are given safe passage and are considered not susceptible to lawsuit or prosecution under the host country's laws (although they can be expelled). It was agreed as international law in the Vienna Convention on Diplomatic Relations (1961), though the concept and custom have a much longer history. Many principles of diplomatic immunity are now considered to be customary law.
If the crime is considered serious they waive immunity; this tends to only happen when the individual has committed a serious crime, unconnected with their diplomatic role (as opposed to, say, allegations of spying), or has witnessed such a crime. Alternatively, the home country may prosecute the individual. Many countries refuse to waive immunity as a matter of course; individuals have no authority to waive their own immunity (except perhaps in cases of defection).