I have not taken the lock apart so I don't know how it is actuated. Seems like it would be actuated by a solenoid. If it is a remote solenoid with a cable I would think its a corroded cable or sticky solenoid if it is not staying locked.
However, my car does similar electronic magic as well. It seems like pushing the small button on the glass lid many times makes the car angry. This makes the whole system freak out. Same thing happens when you turn the headlights on and off many times while the car is off. Pretty soon no lights work not even the brake lights. Once the car is started it resets everything.
Pushing the small button on the dash seems to reset the rear lock system. My guess is that the trunk lid remote button must be pushed for a long time to open the lid because if you sit on your keys or have them in your pocket, occasional short button pushes will not open the lid by accident. Again, my guess is that the system knows this and sensing many short button pushes makes the system semi disabled. So you are accidentally pushing your key fob button in your pocket or purse many times and then later you go to your car and push the unlock button on the key fob to open the lid but the system has said no way am I opening this lid no matter what with the remote. This makes sense because the system has gone into a safety mode. Think of the possible outcome if the system would let the key fob open the lid. You may accidentally open the lid by a long press in your pocket or purse. I think pushing the button on the inside on the dash is like a reset. Same goes for the rear glass button. If someone tampers with the rear button or it gets pushed a lot I'm thinking the system ignores it until the dash button is pushed as a reset. The regular door unlock button may also be linked somehow as a reset. Also, I believe there is a time limit for the rear glass lid button. Once you use the key fob to unlock the car you have a short time when the glass lid button works. So if after this time you start pressing the glass lid button thinking it should open it will not. So you press it many times and the car goes into disabled mode again. So after the small button does not work you start pushing the key fob remote trunk unlock many times to get to open, and it probably also does not work. You have to think about the people who made this car. They are German engineers. EVERYTHING they do is with logic. Why would anyone need to push buttons more than once. If you push a button once it should work. Knowing this, the logical engineers know that if a button is pushed repeatedly you are probably drunk a thief or stupid or all three or any combination of the three.

1. Start the car
2. Turn off car
3. Push dash button, glass lid should pop
4. Open glass lid and close again.
5. push glass lid button, glass should pop
6. Close glass
7. Hold down trunk key fob button, should pop
8. Close glass lid.
As a test you could press the glass lid button many times and see if it quits working. Same for the key fob button, many short inputs. If it then goes crazy start with step one.