No one can give anyone permission to break the law
That includes you giving permission for someone to hit you if, without that permission, their doing so would be illegal.
There are circumstances where it is legal to hit people, for example, in the context of a sporting event like boxing, football or another contact sport. Or in self-defence which does not extend to punching someone who provokes you: you must have a reasonable fear of immanent (or actual) violence and self-defence is limited to the minimum force necessary to resolve the threat (what this is depends on jurisdiction).
Punching someone who merely says "hit me" or "go ahead, take a swing" would be illegal, however, if the entire circumstances were such that the person to whom this was said had a reasonable apprehension of immanent violence then self-defence may make this legal. Similarly, punching someone who has hit you first is only lawful if the purpose of your punch is to stop them hitting you again or to place them under arrest for the crime of hitting you - if they hit you and ran away you are not permitted to use violence against them because you are no longer in danger unless you are subjecting them to reasonable force in the course of making an arrest.