What causes the doors to lock automatically on a 1996 Hyundai Sonata The door lock switch has not been pushed and they don't do it immediately?

I had the same problem with my 1999 sonata when it was brand new. I would leave the car unlocked in my drive and come back out in a few minutes and the doors would be locked. After many trips to the dealer, they found a short in the right front door switch. I haven't had any problems since they replaced it.