As stated, the question could be taken wrong. Instead of asking an indirect question to get information you need to figure something else out, ask what you want to know directly so they aren't left wondering why you're asking them. Presumably you want to know if you're preventing them from sleeping, so just ask that:
It's getting a bit late. I'm not keeping you up, am I?
Then there's no doubt about having their privacy invaded or your intentions.
However, I would challenge whether you really need to ask this at all. If the other person needs to get to sleep, then they're able to say so without you prompting them. Even if they are choosing to stay up late to chat with you, that's their choice to make. It's a bit insulting to try to enforce another person's bedtime.