This is a long post - but I wanted to share my experience with correcting this issue without a trip to the dealer.
You can give it a try, though if your hatch lock has failed it will require replacement.
My power liftgate would move down toward the closed position but not latch, then would reopen on its own.
Manually closing the liftgate would not allow the latch lock to engage, so the car would beep and a warning would be displayed on the instrument cluster.
Side note - Prior to this, pressing the liftgate handle switch (near the license plate lights) would not open the liftgate 100% of the time - sometimes it needed to be pressed twice. Also, the liftgate would occasionally open all the way then start closing on its own.
Again, the problem I was trying to correct was the liftgate not latching, and reopening by itself.
I tried this reset procedure first:
After doing that, the liftgate would beep when pressing any of the opening buttings, but would not move on its own. This happened regardless of liftgate position - all the way up or down.
I tried the emergency liftgate release from the inside:

This didn't seem to do anything, and it didn't feel like it was catching. I believe this is because the liftback latch was stuck in the "unlocked" position.
I then used a pry tool (a flathead would work) to turn the liftback latch counterclockwise - to the locked position. I then heard the lock motor moving, something that hadn't been happening while experiencing the problem. If you move the latch and don't hear the motor, it's possible the motor has failed.
Of course, while in the locked position, you shouldn't attempt to close the liftgate. So I then used the tool to move the latch clockwise to the open position. This activated the lock motor and the latch unlocked the rest of the way on its own.
I then manually pushed down the liftgate to close it, since the buttons still would not move it. Once I closed it, the latch lock motor engaged the lock.
From that point on, it opened, closed, and locked normally using any of the buttons.
I suspect the issue is with the liftback latch not being perfectly aligned on some cars. This could have something to do with the rubber stops on the liftback and where the height of the latch ends up.
If I continue to have problems I'll adjust the height of the rubber stops and report back.