thomas,
Do you have an electric tailgate lock installed, and is that what is not always working...requiring you to use your key to unlock the tailgate.. Or if you have an electric lock and it is wired to the back doors, you have to press the unlock button TWICE on the remote so the tailgate will unlock when the back doors unlock...This is the most common way the electric tailgate locks are wired.
If you do not have an electric tailgate lock, then Steve, is correct...there is something loose or broken in the lock and probably going over a few bumps may be causing the tailgate to lock.
...Rich