The day lasts 24 hours just because the humans wanted to share it in such manner.
There is nothing in nature that is related to the hours, minutes and seconds. This change in time the humans made according to their wish.
But there is something in the nature of what is going on in one day.
Every time when the Earth turns around its axis, we call this period a “day”. Using the stars, scientists can accurately measure the time with Sidereal.
One “Star” day starts when one star passes through one meridian, and lasts until the moment when it passes this meridian again.
As the time is divided in hours, minutes and seconds, we can exactly tell how long lasts one “Star” day: 23 hours , 56 minutes and 4.09 seconds.
But since it would be difficult to use in practical life the “Star day” we take that the day lasts 24 hours, and we add one day to the leap year (February 29th) to compensate for these differences.
In the old days, people thought that the day lasts from sunrise to sunset.
The duration of the night was not taken in consideration. The old Greek people reckoned that day lasts from one to another sunset, and the Old Romans from midnight to midnight.
Until the construction of the Sidereal, it was considered that both day and night last 12 hours.
Such division was not practical, because the length of day and night differed in certain seasons.
Today in most countries, with law is established that day lasts 24 hours, from midnight to midnight, according to the Old Roman measuring.
Sidereal time vs solar time. Above left: a distant star (the small red circle) and the Sun are at culmination, on the local meridian. Centre: only the distant star is at culmination (a mean sidereal day). Right: a few minutes later the Sun is on the local meridian again. A solar day is complete.