The Every-day Book, by William Hone, published 1827
To explain, to those who may be ignorant of the practice. On Twelfth-night in London, boys assemble round the inviting shops of the pastrycooks, and dexterously nail the coat-tails of spectators, who venture near enough, to the bottoms of the window frames; or pin them together strongly by their clothes. Sometimes eight or ten persons find themselves thus connected. The dexterity and force of the nail driving is so quick and sure, that a single blow seldom fails of doing the business effectually. Withdrawal of the nail without a proper instrument is out of the question; and, consequently, the person nailed must either leave part of his coat, as a cognizance of his attachment, or quit the spot with a hole in it. At every nailing and pinning shouts of laughter arise from the perpetrators and the spectators. Yet it often happens to one who turns and smiles at the duress of another, that he also finds himself nailed. Efforts at extrication increase mirth, nor is the presence of a constable, who is usually employed to attend and preserve free "ingress, egress, and regress," sufficiently awful to deter the offenders.
If you read the e-text, you'll see, further down, mention of Twelfth-cakes. Colonial Williamsburg offers a recipe. And here's a BBC story, complete with wrong date (????)