Haydn himself explained the origin and difficulty of writing the work when the publisher Breitkopf & Härtel issued (in 1801) a new edition and requested a preface:
Some fifteen years ago I was requested by a canon of Cádiz to compose instrumental music on the Seven Last Words of Our Savior On the Cross. It was customary at the Cathedral of Cádiz to produce an oratorio every year during Lent, the effect of the performance being not a little enhanced by the following circumstances. The walls, windows, and pillars of the church were hung with black cloth, and only one large lamp hanging from the center of the roof broke the solemn darkness. At midday, the doors were closed and the ceremony began. After a short service the bishop ascended the pulpit, pronounced the first of the seven words (or sentences) and delivered a discourse thereon. This ended, he left the pulpit and fell to his knees before the altar. The interval was filled by music. The bishop then in like manner pronounced the second word, then the third, and so on, the orchestra following on the conclusion of each discourse. My composition was subject to these conditions, and it was no easy task to compose seven adagios lasting ten minutes each, and to succeed one another without fatiguing the listeners; indeed, I found it quite impossible to confine myself to the appointed limits.
The priest who commissioned the work, Don José Sáenz de Santa María, had reconditioned the Oratorio de la Santa Cueva, and paid Haydn in a most unusual way - sending the composer a cake which Haydn discovered was filled with gold coins.
(Source: Wikipedia)