From what I understand, an indulgence can technically be granted for any reason that isn’t sinful (if a bishop tried to grant you one, for example, for stealing from your neighbor, it would be invalid). St. Paul granted an indulgence to the penitent incestuous man of Corinth when he demonstrated sufficient repentance and love of God and neighbor. As such, the Church usually grants them to encourage and reward turning from sin through acts of devotion, piety, and charity. The indulgence related to the Holy Doors, for example, encourages pilgrimages to those sites.
I don’t think there is a specific formula needed to attach an indulgence to particular act, the bishop or Pope just needs to make his will in the matter known. This is usually done by promulgating a written decree of some sort, but it could also be granted even orally. For the Urbi et Orbi, the indulgence is announced orally just before the blessing and is also contained in the very words of the blessing the Pope makes. It is now also contained in a standing written decree, but I don’t think it would have to be to be valid.