I have been curious about the question myself. I couldn't seem to find any RCW defining when it is lawful.
Common sense tells me that if they are detaining you for questioning or arresting you as a suspect in a crime they can certainly ask and you'd have to comply. Beyond that, I couldn't begin to guess how the courts would interpret that today.
Perhaps someone with experience as a defense or prosecuting attorney can tell us?