We don’t recommend it, though lots of people do it. The hair can get very matted in the back, especially in longer wigs, so it’s a pretty quick way to destroy your hair if you're not careful.
If you need the hair to feel comfortable while you sleep, we recommend purchasing a short, inexpensive, comfortable wig just for sleeping in. One of our favorites is Allure (the non-monofilament version) by Jon Renau.
Wraps and sleep hats can also be worn if you feel your head gets cold at night.
Turbans coupled with halos are another common solution to this issue.