This is sometimes done as a security concern to keep employees from swiping data or causing havoc. An employer may also assume that an employee with 2 weeks left will have tanking productivity, so why keep them around? The good employees will try to wrap things up and do knowledge transfer, but this certainly isn't going to be the majority of people.
The part where the employee has self-selected themselves as a risk. Lots of the major companies have capability to identify when an employee is downloading tons of data and files, but for the less sophisticated ones, you pretty much just have to look out for motive, and an employee giving notice is probably disgruntled...which is at least a little bit of motive.