We undergo a process called respiration which is essential for us to live. Similarly plants go through two processes - Respiration and Photosynthesis. These two processes are completely different from each other. In photosynthesis the plants take in carbon dioxide and release oxygen while in respiration there is intake of oxygen and release of carbon dioxide. These two processes are always done by the plants. During the day there is enough sunlight and the plants carry photosynthesis on a large scale but during the night respiration takes place. So at night when these plants release carbon dioxide and we release carbon dioxide there is lack of oxygen. That is why it is not advised to sleep under a tree during light.
Hope it helps :)