It’s derived from the Old English term hrōst, which referred to the wooden framework of a roof. Old English birds would perch and sleep on old English hrōsts, and by the early 16th century that’s essentially what roost came to mean. As a noun, it generally denotes a place where birds sleep for the night; as a verb, it means to settle in for the night.
Roost is also the root of rooster, which refers to a male chicken. The term used to be roost cock or just cock, but during the Puritan movement of the 16th and 17th century, some folks became uncomfortable with the association of cock with the male sexual organ. So Puritans began calling male chickens roosters and on those rare occasions when they needed to refer to the male sexual organ they probably called it the ‘male sexual organ’ (which I suspect is one of the reasons the Puritan movement died out).
The term has worked its way into idiomatic expressions. To rule the roost means to be the controlling member of a family or group. There was a time when that was assumed to be somebody with a male sexual organ, though to assert that definition these days would be to risk the rooster becoming a capon (which, by the way, has the same etymological root as hatchet, which is alarmingly appropriate).
When wicked deeds or words cause discomfort to the originator, we say the chickens have come home to roost. That phrase actually comes from an 1810 poem by Robert Southey (who is best known for writing The Story of the Three Bears, which is now known as the story of Goldilocks). In his epic poem The Curse of Kehama, Southey wrote:
“Curses are like young chicken: they always come home to roost.”
Southey, it has to be said, stole the concept from Geoffrey Chaucer, who basically said the same thing (only with a lot more vowels) in The Parson’s Tale:
And ofte tyme swich cursynge wrongfully retorneth agayn to hym that curseth, as a bryd that retorneth agayn to his owene nest.
Modern bryds, of course, no longer need to retorneth agayn to their owene nests. Nor do they need an Old English hrōst. If they want to roost, all they have to do is find a convenient spot to plant their feathered butts and go to sleep.