Because it is to drink coffee when there is still a feeling of cheerfulness - in this case, the brain receptors are not filled with melatonin, i.e. sleep hormone.
Coffee acts as a stopper, preventing melatonin from sticking to receptors, making you feel sleepy (which you probably want to get rid of)
When you already want to sleep, but you can't, you need to use the "coffee nap" tactic:
1) drink coffee
2) nap for about 20 minutes
This short nap will allow the receptors to release sleep hormones again, and caffeine to take their place.
Because coffee itself, contrary to popular belief, has not a stimulating, but an intoxicating, dramatically calming effect.
A surge of vivacity and a surge of energy after drinking it is associated with the ultimate mobilization of the brain and body, which having received poison (from his "point of view"), he begins to actively overcome its tranquilizing effect.
On this rise you have been acting for some time. When the strength of the body to fight the tranquilizer decreases, a natural decline follows.