This has almost the same meaning as "ins Fettnäpfchen treten" (to blunder), i.e. doing/saying something that one should not have done or said.
This saying has its origin in "Schützenfesten". There, a billy goat was the consolation prize. So if you missed your target, you shot a goat. (I didn't know that and just looked it up)