Core body temperature is not constant across the day. It follows a rhythm of about a degree, and the timing of sleep is tied closely to the shape of that curve.
The curve has a fixed shape
Core temperature reaches its lowest point in the hours before habitual waking and its highest in the late afternoon or early evening.
The rhythm is generated by the circadian clock in the hypothalamus and persists in the absence of external time cues, so it is internally driven rather than a by-product of activity.
Exercise, meals and ambient conditions push the curve up or down without changing its underlying shape.
Sleep onset tracks the falling limb
Sleep begins most readily while core temperature is dropping, and the steepest part of the decline coincides with the usual window for falling asleep.
Waking follows the rising limb, which begins before the person wakes rather than after.
Attempting to sleep while temperature is near its evening peak is characteristically difficult, which is one component of what shift workers and travellers experience.
The body sheds heat through its extremities
Core temperature falls by moving heat outward. Blood vessels in the hands and feet widen, increasing blood flow to the skin, and heat is lost to the surroundings.
Skin temperature at the extremities therefore rises shortly before sleep while core temperature falls, and the two move in opposite directions.
The degree of that vasodilation is among the better physiological predictors of how quickly a person falls asleep.
Warming the periphery can assist the core decline
This mechanism explains why a warm bath in the evening is associated with easier sleep onset, which sounds contradictory.
Warming the skin triggers vasodilation, and once the person leaves the water the widened vessels shed heat rapidly, accelerating the core drop.
Cool bedding and a cool room support the same process by maintaining a gradient for heat to move down.
Melatonin and temperature are part of one system
Melatonin release begins in the evening under the control of the same clock, and one of its actions is to promote peripheral vasodilation.
Light exposure in the evening suppresses that release, which delays both the melatonin rise and the temperature fall.
Persistent difficulty sleeping despite favourable conditions is worth discussing with a clinician, since circadian timing disorders and other sleep disorders are treated differently from one another.