The short answer
Nighttime — specifically the window right before sleep — is when your brain has the fewest external inputs competing for attention: no screen, no task, no conversation. That absence of competing input is exactly the condition under which unprompted, involuntary memories are most likely to surface, which is why the same old embarrassing moment that never bothers you at noon shows up reliably at 11pm.
The mind-wandering mechanism
Neuroscience research on what's called the brain's default mode — the network that activates specifically when you're not focused on an external task — helps explain the timing. Landmark imaging work identified a set of brain regions that become more active during rest and mind-wandering than during focused tasks. Falling asleep is one of the most reliable everyday triggers of that default-mode activity, which is also when spontaneous, self-referential memories are most likely to surface uninvited.
Why it's not really about the memory itself
The memory that surfaces at night usually isn't objectively worse than one you could recall calmly during the day — the timing does most of the work. During the day, a new task or conversation typically interrupts the memory within seconds. At night, there's nothing to interrupt it, so it runs longer and feels more intense simply because it's uncontested.
What tends to help
Since the core issue is lack of competing input rather than the memory's content, approaches that give the mind something small to do with the moment — rather than trying to blank it out entirely — tend to work better than pure suppression. Marking that the thought occurred, even briefly, gives it somewhere to go without requiring you to fully process it at 11pm, which is rarely the moment you have the composure to do that anyway.