High‐frequency oscillatory activity in cognition‐related neural circuits during wakefulness consistently induces the growth of dendritic spines and axonal terminals. Although these structural changes are essential for cognitive functions, it is hypothesized that if these newly expanded structures fail to establish functional connections, they may become superfluous. Sleep is believed to facilitate the reduction of such redundant structures to maintain neural homeostasis. However, the mechanisms underlying this pruning process during sleep remain poorly understood. In this study, that melatonin type 3 receptors (MT3Rs) are selectively expressed in the stellate neurons of the medial entorhinal cortex (MEC) is demonstrated, an area where high melatonin levels are detected during sleep. Activation of MT3Rs during sleep initiates the shrinkage of dendritic spines in stellate neurons by downregulating neural network activity and dephosphorylating synaptic proteins in the MEC. This process is disrupted when MT3R expression is knocked down or when MT3Rs are blocked during sleep. Notably, interference with MT3Rs in the MEC during sleep impairs the acquisition of spatial memory but does not affect object memory acquisition following sleep. These findings reveal novel molecular mechanisms involving melatonin and MT3Rs in the regulation of dendritic spine shrinkage during sleep, which is crucial for the acquisition and consolidation of spatial memory.