If you called a judge a "goat fucker" in their court room, I suspect you would be in some hot water.
One could argue there's not a huge leap between rules/laws requiring respectful behavior towards judges in a court room and a law requiring respectful behavior towards world leaders...
Edit: Not sure why I'm being downvoted -- I'm not defending the German law, just pointing out that it's not that different from contempt-of-court punishments in the US.