The trunk will do that if there's an obstruction of some sort.
Mine used to beep and not close sometimes for no apparent reason - it seemed mostly on hot days. Then I noticed there are two threaded rubber bumpers on the underside left and right corners of the trunk lid (see pic).
View attachment 317452
There is a corresponding plastic landing pad on the edge of the trunk opening that makes contact with the rubber bumpers when closed.
If you look closely the rubber bumpers on the trunk lid are threaded, so giving them a twist moves them slightly closer or further from the trunk lid. I suspect your bumpers are slightly out of adjustment, probably extending slightly too far out i.e. hitting the landing pad slightly too early, causing whatever closing-sensor to trigger and not allow trunk to close.
I recommend marking their current rotation position with chalk or something for reference, then giving the rubber bumpers a slight clockwise twist (into the trunk lid) to slightly lessen the contact. That solved it for me (I think when it was hot out the expansion of the bumpers caused it to sometime fail to close).