What causes King's Quest IV to transition from day to night?

Solution 1:

According to this guide, night will fall at 9:00 PM.

In Tamir, night falls precisely at 9:00 PM. If night has not already fallen, it soon will. Wait until nightfall. You can always check the time by the clock inside the mansion.

However, according to this post, it looks like, unlike its predecessors, King's Quest IV will automatically transition from day to night once you have completed everything necessary during the day (to save you the time you'd have to spend idling until 9:00 PM):

Those who hated sitting around on KQIII's pirate ship will be thankful to hear that once you've finished all of the tasks you need to do during the day, nightfall is triggered automatically, regardless of what time it is in Tamir.

However, the 9:00 PM mark is also mentioned in the same article, though it sounds like it's not very difficult to finish up what needs to be done during the day within the allotted time limit:

The game's timed element theoretically means that day could break before Rosella completes her quests, resulting in a game-over scenario, but in the dozen or so times I've played this game it's never happened to me, and I've never heard complaints about it from anyone else, either.

As to how time is tracked, from the wikia:

This chapter is the only one in the official King's Quest series where the action takes place during a specific and limited amount of time— the events of the game cover about 24 hours (8:00 A.M. to 8:00 A.M.). In fact the game, much like King's Quest III, had a real time clock and time would pass even if the player wasn't solving puzzles.

Solution 2:

How time works

King's Quest IV has an internal clock that runs in the background. You can check the current time by going into the old mansion and typing in the command time (not look clock, which describes the appearance of the clock).

King's Quest IV Time

Time progresses at a rate of roughly 1 in-game minute per 10 real-world seconds.* This rate is unaffected by the animation speed for the game. The internal clock pauses if you have an open text prompt or message (e.g. descriptions of something you're looking at).

The game begins at 8:00 A.M. and night falls after 9:00 P.M. This means that you have 13 in-game hours, or 78 real-world minutes (plus any time you spend with text prompts or messages open) to find the magic fruit before night falls.

* At least, I think it’s 1 in-game minute per 10 real-world seconds. Sometimes it seemed to line up with this, especially when I am checking minute by minute, but if I go a long time between checking, like when I just let the game run in the background, it seems to be slower. I wonder if it’s affected by CPU clock speed and if ScummVM/DOSBox settings affect it.

Warnings about approaching night

At 8:15 P.M., a message appears warning Rosella that it will be night soon.

King's Quest IV — 8:15 P.M.

This message reappears at 8:30 P.M., 8:45 P.M., and 9:00 P.M. After 9:00 P.M., transitioning from any outdoor location to any other outdoor location (e.g. outside the mansion to the graveyard) will trigger the “Like a heavy blanket, darkness enfolds you” cutscene.

However, transitioning between interior locations (e.g. the rooms of the mansion) or an interior location to an outdoor location and vice versa (e.g. entering and exiting the mansion) will not trigger the night and the game will still treat the game as being in the day. If you are in this state, no further messages warning you of the impending night will appear and it will still appear to be day, even at 9:15 P.M. etc.

If you do find the magic fruit before time runs out, then when you leave the area, the time will jump to 9:00 P.M. and night will fall, preventing you from needing to wait around for it to happen.

Approaching morning?

I'm unsure if there is a similar amount of time for approaching morning. More research is necessary.