The term probably dates back to fifteenth-century England, where strict laws were passed to prohibit bakers from underweighing their bread.
Since weights could not be precise, bakers adopted the practice of giving 13 loaves on every order of 12.
However, another theory has to do with the common folk phrase devil’s dozen, meaning 13.
Bakers of the Middle Ages were in such bad repute that the words baker and devil were synonymous.
Thus a devil’s dozen could also be called a baker’s dozen.