Whilst it might not be very bright to steal a plane and then log the flight, my point is that I think the hours would 'count'. You would be, after all, still flying the plane!
If the statement "Every aspect of the flight needs to be legal in order for you to act as commander" was true, then thousands of people are logging time illegally. The word 'every' opening the door to all sorts of (very minor in the most case) violations.