I have noticed that the only string that ever breaks on my classical guitars is the D string. And like you, I can only remember this having happened when I'm not playing them. Conversely, I only seem to break the top string on my electric and acoustic guitars, and this usually happens while I'm playing.
As far as classical strings go, I think it is most likely to be a statistical phenomenon. When playing classical guitar, the strings are barely under any more stress than when you are not playing. You are unlikely to be adding extra stress to the strings by bending them (or by using a pick?). So, the majority of the stress on the string is its own tension, which is always the same, being played or not. Statistically, unless you are a very committed player, you will spend more time not playing your guitar than playing. Therefore, all things being equal, the strings are more likely to break when you are not playing.
As I say, I create a lot more stress on my electric guitar strings when playing (and they are stronger anyway?), so I'm not surprised that they break while I'm playing.
EDIT: this previous post adds information about why D strings break more often on classical guitar. It has a lot of useful information, but these three points seem to be key:
- The D is a wrapped [wound] string, and more likely to break than a solid string
- It has thinner wire than the other two bass strings
- It is under the highest tension of the three bass strings
However, if you do notice that your A and E strings break regularly too (this certainly doesn't happen for me), it may be a problem with your guitar (usually bridge or nut), or something to do with how you store it.