In Le Mans, all cars have 3 lights on the side.
The color part is easy: It is the color of the series you are racing in.
But sometimes 1 is lit, other times it is 2 or 3.
What is the logic of those lights?
These are apparently called "leader lights", and they indicate that the car is currently in the top three in its class. If you have one leader light on, you're currently 1st in your class; two leader lights means you're 2nd; three means you're 3rd; and if they're all off, that means you're 4th or below.
As an example, you can see in your screenshot that the #22 car is currently leading the LMP2 class, and accordingly, it only has one leader light on.
I believe that the purpose of these lights is to make it easier for spectators at the track - who don't have the TV graphics available to them - to tell who's actually winning. Endurance racing has much greater field spread than, say, Formula One, with cars often ending up multiple laps behind the one in front, making it hard to tell at a glance who's in what position.
First answer is very good.
So I add just a small addition with the color code for who reads in future.
The lights make it easier to spot the first 3 leaders for each category, especially during the night for people who are spectators there at the track.
LM P1 or Hypercar LMH / LMDh - red lights (also the car number is on red background with P1 or HYPER CAR red text next to it)
LM P2 - blue lights (the car number is on blue background with P2 blue text next to it)
GTE PRO - green lights (the car number is on green background with PRO green text next to it)
GTE AM - orange / amber lights (the car number is on orange background with AM orange text next to it)