To keep customers happy and avoid fines or beatings.
Until 1266, when the Assize of Bread and Ale Law came into force under King Henry III, rules and regulations around the sale of goods were scant. People often got ripped off by local merchants. The new law, rigorously enforced by royal regulators, decreed that the price of bread and ale should be set relative to the price of ingredients.
In the case of bakers, the price of bread was dictated by the price of wheat, and anyone found to be selling underweight loaves would be fined or beaten. Since many bakers did not possess a set of weighing scales, it was safer to throw in an extra loaf.
Often the thirteenth “loaf” in a baker’s dozen was actually a smaller end piece or crust. But whatever it was, if a happy customer was the result and a beating was swerved, everyone went home an unbruised winner.