The exception is often called a Romeo and Juliet exception colloquially when applied to statutory rape laws. See, e.g. here. It is an exception to the age of capacity to consent to sexual conduct, not an exception to the capacity to consent to a contract.
When children are very young (typically in the range of 7 to 12 as set by statute of common law, it is 6 in North Carolina) they lack the capacity to commit a crime, which has to do with the age of the offender and not the mutual ages of those involved.
Is the principle described above called something? How old is it? Did
the Romans apply a similar concept? The medieval Catholic church?
The principle that you described is a misunderstanding of the law and is incorrect. No jurisdiction has adopted it in the sense that you articulate. When these instances are not punishable as crimes they are not punishable for different reasons. So, the question of "how old is it?" is a category error that has no answer.
The medieval Catholic church did not have any criminal or contract jurisprudence. Both of those domains were handled by secular officials, usually either feudal lords or the officials of a "free city". In the medieval period, feudal secular law was often arbitrary and often came down to the personal whims of the individual holding the title. As @hmvsm appropriately notes, however, it did have doctrine about when a child was morally responsible for sins, but final adjudication of whether you sinned or not was ultimately determined in the afterlife, and the church doctrine of forgiveness of sins made the issue moot to a great extent.
The Roman Empire, of course, did have secular laws, but its laws in the area of contractual capacity, which are largely replicated by modern European civil codes, didn't contain the principle that you propose. To the best of my knowledge, the modern concept of statutory rape was unknown in the Roman world. The lack of hard age based cutoffs was, in part, because vital statistics record keeping was nowhere near universal, so many people did not even know their exact age in a legally provable manner. Approximate age in the very late Roman Empire would often have been determined based upon time elapsed since an infant baptism as recorded by church officials, but Christianity went from being very rare to universal between about 275 CE and 450 CE, and Rome fell not long after that point.