It's because the door lock inside the door is malfunctioning and not triggering the switch to let your truck know the doors open. Your interior lights don't turn on either when this happens, correct?
If that's the case, you can always get some electronic grease spray and spray it and hope that works. If not, you'll need a new lock mechanism.