The modern end-of-day ceremony known as Retreat originated in the 16th century, when it was called Watch Setting, and is referred to in the Rules of Ordynaunces for the Warre of 1544 as well as by Robert Barret in his Theorike and Practice of Moderne Warres of 1598, where he says 'The Drum Major of the Regiment had to advertise (by beat of drum) those required for the Watch.'
The first work describes the ceremony thus:
'Half an hour before the Gates are to be shut, which is generally at the setting of the sun, the Drummers of the Post Guards are to go upon the Ramparts and beat a Retreat to give notice to those without that the gates are to be shut. As soon as the drummers have finished the Retreat which they should do in less than a quarter of an hour, the Officers must order the Barriers and Gates to be shut.'
So besides warning the guards for duty Retreat also warned those outside the perimeter or fortress etc to retire to safety within for the night.
On the battlefield Retreat signalled the end of the soldiers' day, as fighting usually concluded at sunset. Troops would assemble, the roll would be called, and those who had fallen would be suitably honoured by their comrades who had survived.