I’ve read that the underlying assumption here is basically that since such insults potentially damage the relationship between Germany and the foreign state, Germany is an injured party and as such involved in the process.
But it’s also just an ancient law …