Days, months and years are all based on easily observed natural events. But where did the "hour" come from? Why 24?
According to a book I have, the origin lies with the ancient Egyptians and comes to us via the Babylonians, Greeks and the Romans.
Sometime in the third millenium (3000 - 2000 B.C.) the Egyptian administration felt the need for an official year, nicely sub-divided. They observed (most likely) that the "first rising" of the star Sirius was an annual event, synchronous, but not co-incident with the annual flooding of the Nile. This "first rising", known more properly as the heliacal rising, is when both the Sun and a Star rise at the same time in the dawn hours. They counted 365 days to the next heliacal rising of Sirius, and then divided the year into 36 official weeks of 10 days each - the odd five days being discounted.
Why 36 weeks? They, or the Babylonians (not sure which), also identified 35 other stars or star groups which had more or less evenly-spaced heliacal risings throughout the year.
Then they proceeded to divide the night into hours, based on those same star groups which should have led to an 18-hour (half of 36) night! However, on many nights, only 12 of those 36 stars or star groups were reliably visible as they rose, therefore the night was evenly divided into 12 hours and so was the day.
Thus, about 5000 years ago, the 24-hour day was born!