The Decretum Gratiani ["Decrees of Gratian"] is a collection of canon laws published by the jurist Johannes Gratian c.1150. It includes the line "Let the priest who dares to make known the sins of his penitent be deposed."
We are not sure when this idea was first expressed, but the Fourth Lateran Council of 1215, which laid down rules for the whole Catholic Church, explained the practice thusly:
Let the priest absolutely beware that he does not by word or sign or by any manner whatever in any way betray the sinner: but if he should happen to need wiser counsel let him cautiously seek the same without any mention of person. For whoever shall dare to reveal a sin disclosed to him in the tribunal of penance we decree that he shall be not only deposed from the priestly office but that he shall also be sent into the confinement of a monastery to do perpetual penance.No explanation is given for this secrecy, but an English jurist in the 1400s, William Lyndwood, explains that the sacrament involving confession practically by definition requires that the "secret" be kept quiet. Even the secular authorities recognize this relationship. A priest may suggest to a confessed criminal that he turn himself over to the courts, but the courts do not compel a priest to reveal what he knows.
Well, not all secular authorities. In March 1393, John of Nepomuk (born c.1345) was tortured and thrown into the river by King Wenceslaus IV (who was otherwise fairly tolerant). Wenceslaus was angry with him because he was the Confessor to Wenceslaus' wife, the Queen of Bohemia, and would not tell her husband what she talked about. John was canonized as Saint John of Nepomuk, and is considered the first martyr because of the Seal of the Confessional and the patron saint against false witness.