In the heat of the moment I've changed lenses with the camera turned on, I've had nothing untoward happen, but of course I don't know if it's attracting more dust than usual. So if you do it accidentally leave the camera on it's not the end of the world, but I woudn't recommend it.
The camera knows when you've removed the lens however, indeed it knows what you're doing before the lens is physically removed because the lens contacts which give the camera data about the lens disengage before the lens can actually be removed, so I'd be surprised if the sensor is still activated at that stage. However I of course stand to be corrected.
Indeed, on the broader topic, isn't the sensor only charged when it's being used, ie at the moment of taking a photo or live view? I know Nikon don't like the sensor being activated for long periods due to heat build up, I think 5 minutes is the limit. The sensor itself isn't used for focusing and metering outside live view.