It only works while being worn when sleeping -- while you are wearing it, for each sleep interval calculation (nominally every 1 second, but that is not necessarily correct) the boost in HP and energy you recieve is increased by 50%
It doesn't matter what you are wearing* when you queue sleep, when you begin to sleep or when you end sleep, only what you are wearing during the time you are asleep.
* note: prayer bonus, whatever it is, may be very dependent on when you change clothes -- no one outside of the ~dev community knows