It is specifically covered in the NFL rules for 2017 as rule 12, section 3, article 2
the defense shall not commit successive or repeated fouls to prevent a score.
Penalty: For successive or repeated fouls to prevent a score: If the violation is repeated after a warning, the score involved is awarded to the offensive team.
In the same section, article 4 refers to "Palpably Unfair Acts" https://en.wikipedia.org/wiki/Palpably_unfair_act.
A player or substitute shall not interfere with play by any act which is palpably unfair.
Penalty: For a palpably unfair act: ...... The Referee ...... enforces any such distance penalty as they consider equitable ...... The Referee may award a score. See 15-1-3.
So, in my example above, once the defense have committed two fouls, moving the ball to 1.25 yd line, the referee would give them a warning : do that again and I'll give a TD under article 3.
While, if the offense has the ball 1st and Goal at the 1 yd line, and a linebacker took a shot at the QB before the snap, thinking that it's only an 18 inch penalty - that could be a TD (and ejection) under article 4.