For most of human history, there is little evidence that we wore special night time clothes when we wanted to have a snooze.
Nightgowns as a concept date back to at least 1530, when French linguist John Palsgrave wrote "short coats and tight trousers were a great offence to old writers accustomed to long nightgown clothes", though this likely did not refer to dedicated sleepwear but more loose clothing to be worn around the house.
In the 1800s and 1900s, these nightgowns became more specialized as sleepwear, as well as becoming more refined. During the 1800s the West began wearing nightwear, influenced by "pae jama" or "pai jama" – a type of loose-fitting pants (trousers, for non-Americans and Australians) worn in the Middle East and South Asia, tied with a cord.
They weren't popular, however, until the early 1900s. It turns out what really got pajamas selling was a bombing raid.
“Before the turn of the 20th Century, both men and women would have quite often worn nightgowns, so even pyjamas for men were relatively new around 1900," Lucy Whitmore, who wrote about fashion narratives of the First World War for her PhD thesis explained to the BBC. When Zepplin air raids took place on Britain, that changed.
“Magazines started suggesting that women should either wear more practical nightwear – should they have to run from their beds in the middle of the night – or nightwear that really made them look presentable should they bump into their neighbours at 3am.”
As well as looking more presentable, pockets in pajamas were also much more practical in emergency situations. Sleeping suits – sort of like a onesie but less comfortable as you're only wearing it because you might be bombed – were also recommended for nightwear. These didn't catch on, but by the end of the war around a third of women were wearing pajamas to bed. They have increased in popularity since then, worn for comfort rather than risk of looking stupid at 3am during an actual air raid.