The answer to this question is not easy. Honestly, the answer really depends on the person. While your feet and legs need time to breathe outside of socks if you aren’t wearing them all day then wearing them through the night may be fine for you. More often than not you would not sleep in your compression socks.
Typically you want to wear socks during times that you are sitting for a long time or standing for an extended period of time. Post-surgery or injury may have different instructions from your doctor in which case you will want to follow what they have told you to do.