Is there any legal defenses if you are on the highway and a cop pulls you over and gives you a speeding ticket while going the same speed as surrounding traffic? It seems dangerous to goo too slow so I was thinking maybe Quod est necessarium est licitum?
If you were moving "with the flow of traffic" but over the limit, you were still breaking the law, and the cop can choose which car or cars to stop on any basis or none (except ones forbidden, such as racial in the US). This is almost surely not a valid defense, not in any jurisdiction that I know of at least.
If you can show that to slow to the speed limit would have actually been unsafe, you might have a defense, but that is going to be hard to get a court to accept.