In the Laws of the Game, there is a small—yet non empty—set of offences for which the referee must not immediately blow his whistle as he usually does for 'normal' fouls, but must instead allow play to continue, and caution the guilty player when the ball is next out of play.
Examples of such offences include swicthing places with the goalkeeper without informing the referee beforehand (Law 3.5):
If a player changes places with the goalkeeper without the referee’s permission, the referee (...) cautions both players when the ball is next out of play
or making unauthorized marks on the field of play (Law 1.2):
A player who makes unauthorised marks on the field of play must be cautioned for unsporting behaviour. If the referee notices this being done during the match, the player is cautioned when the ball next goes out of play.
These are infringements that do not naturally carry a restart with them (e.g. indirect free kick, direct free kick, dropped ball, etc.), since the Laws explicitly forbid the match officials from interrupting the game to deal with them, and only instruct the referee to issue the appropriate disciplinary sanction afterwards.
This said, let's move onto Law 10 (Law 10.1). Here we can read that:
A goal is scored when the whole of the ball passes over the goal line, between the goalposts and under the crossbar, provided that no offence has been committed by the team scoring the goal.
First of all, it's obvious that this paragraph is only referring to those offences that are committed between the restart of play that is chronologically the closest to when the goal is scored and the goal itself, otherwise a team who commits a foul in the first minute of play would be forbidden from scoring a valid goal for the whole duration of the match.
So, to make an example, if a substitute enters the field of play just seconds before his team scores a goal, said goal must be disallowed, and play restarts with a direct free kick from the position of the extra person (Law 3.9) because this is the kind of penalty that is carried by the offence of entering the pitch without the referee's permission (Law 3.7).
But what about the offences I mentioned at the beginning of my question? There's not a specific restart of play attached to them. So, what do you do if a player makes unauthorized marks on the field of play just before his team scores a goal? What if a defender changes places with the goalkeeker without telling the referee, and then the new goalkeeper handles the ball within his penalty area, and throws it with the hands in such a powerful way that it directly enters the opponents' goal? It's obvious that such goals cannot be allowed, but how should play restart?
- Should the match be resumed with an indirect free kick, on the basis that play was interrupted to show a card to a player who was guilty of an offence that is not mentioned in Law 12 (Law 12.2)? Though the game was technically NOT stopped to caution the player—it was stopped because the ball entered one of the goals; the Laws forbid the referee from stopping play solely to deal with these offences, after all. And anyway, where should this free kick be taken? From inside the goal area?
- Should play restart with a goal kick/corner kick, on the basis that the ball crossed the goal line, but a goal was not scored (Law 16 Introduction, Law 17 Introduction)? If so, when is it a goal kick and when is it a corner kick? Should it depend on which player touched the ball last before it entered the goal, as is the case for 'normal' situations involving goal kicks/corner kicks?