Before houses had indoor toilets a chamber pot was always kept under the bed to save a trip to the outside "privy" at night.
In my imagination I can hear the voice of Eloise, a young French House wife stating, “Pierre, I am tired of looking at your full chamber pot when I rise! Hide it somehow!”
Pierre being a very dutiful husband asked the travelling artisan to create a little 'cupboard' he could put beside his bed, so as to not upset his beautiful wife.
Lo & behold, the beginning of the 'Table de Nuit'. Perhaps not the real story but surely believable?
Did you know that the Royals of Europe had servants dedicated to their bodily functions? Many of the titles now in use (e.g. Lord Chamberlain) come from this time. The servants were always present for royal bathroom times, and it was a position of social importance.
But I digress. The main function of a nightstand was to contain a chamber pot. This is why when you open the door our bedside tables have a marble base, originally they would also have had marble lining to the sides and back but this typically gets broken as they are not fixed securely and every time they were moved a marble insert ran the risk of falling over and breaking.