The makura gaeshi, AKA the makura kozō is a type of Japanese spirit, one of the yōkai. Yōkai range from the harmless to the deadly serious (the term is often translated 'demon'), and makura gaeshi cover the entire range.
While local lore varies a lot from place to place and time to time, the most common form of makura gaeshi are mischievous ghosts that act out by stealing pillows, most often snatching them away and leaving them at the sleeper's feet. They may engage in other small pranks, such as tracking ash across the floor or flipping over the entire tatami bed mats.
In a slightly more sinister mode, they may also flip over the sleeper. this can be disturbing or even damaging, and moreover, sleeping with one's head facing north is symbolic of death1, and waking to find yourself rotated in a northerly direction is disconcerting at best, and prognosticative at worst. Some will try to kill you outright, sitting on your chest and squeezing the air out of your chest. Some also blame sleep paralysis on the makura gaeshi.
The makura gaeshi are usually said to be a form of zashiki warashi -- the ghosts of small children -- especially those that died tragically or violently. They are usually firmly linked to the bedroom, and mostly died in the room they haunt. They often take the form of small Nio, monks, or samurai.2 The earliest depiction we have of them, in Toriyama Sekien's drawings, is of a demonic form rather akin to a withered old man. Modern forms are more likely to be that of a small child.
Makura gaeshi translates literally as 'pillow-flipper'; it is also common to write it as makura-gaeshi or makuragaeshi. The term makura kozō is also used, which translates as 'pillow child'.3
Footnotes:
1. The Buddha is said to have died with his head pointing north, and as a result it is traditional to lay out corpses in the same fashion. It is not good news when the ghosts decide to lay you out in funeral position.
2. However, there are some traditions that hold that those who see a makura gaeshi pass out immediately, allowing the makura gaeshi to steal their soul... which leads to death shortly thereafter. So it may not be in your best interests to take a peek.
3. The word kozō is sometimes translated as 'brat'.