Hi Olai,
You are correct in thinking that the question "how was your night" is usually something that gets asked after someone has gone out for the night (e.g. to a party; to a bar; to a concert...). I suppose it could be asked if you spent the night with a (sexual) partner, in a sort of euphemistic way (a euphemism is an indirect way of asking about something rude, explicit, or unpleasant).
For asking about sleep or rest, we probably wouldn't use this phrase. Instead, you could say something like: "Did you have a good sleep?". I suppose an exception might be if there is a particular reason to think that someone's sleep might have been disturbed (e.g. by a newborn baby; noisy neighbours; jetlag...).
You are right in thinking that context is everything :) I hope you find this helpful.