Excessive glucocorticoid exposure during chronic stress causes synapse loss and learning impairment. Under normal physiological conditions, glucocorticoid activity oscillates in synchrony with the circadian rhythm. Whether and how endogenous glucocorticoid oscillations modulate synaptic plasticity and learning is unknown. Here we show that circadian glucocorticoid peaks promote postsynaptic dendritic spine formation in the mouse cortex after motor skill learning, whereas troughs are required for stabilizing newly formed spines that are important for long-term memory retention. Conversely, chronic and excessive exposure to glucocorticoids eliminates learning-associated new spines and disrupts previously acquired memories. Furthermore, we show that glucocorticoids promote rapid spine formation through a non-transcriptional mechanism by means of the LIM kinase–cofilin pathway and increase spine elimination through transcriptional mechanisms involving mineralocorticoid receptor activation. Together, these findings indicate that tightly regulated circadian glucocorticoid oscillations are important for learning-dependent synaptic formation and maintenance. They also delineate a new signaling mechanism underlying these effects.