Problem with rear flap sensor when the interior lighting is switched on

When I turn on the interior lighting when the engine is running, a message is displayed in my driver’s display or flashes on that my tailgate is not closed. In addition, a warning sound resonates (as if driving with a door that is not properly closed). If I turn off the interior lighting again, the problem is gone. Has anyone ever had an experience of this or a guess what this might be all about?