It came from the ancient custom that, when gagaku (traditional court music) was played, "senshuraku," which suggested congratulations, was played as the last number of the day.
雅楽を演奏する際、1日の最後の曲には祝言の意味から必ず「千秋楽」を演奏したという古い風習