What could be wrong if your swimming pool light malfunctions and turns off by itself then after awhile it sometimes turns on again?

Bad switch? Bad connection? Bad bulb? The sensor on the back of the fixture is most likely sensing that the light is overheating or you may have a short. Have a qualified pool tech trouble shoot the system. If the light is an older one then the best course is to replace it. Make sure that the system has a GFCI installed. Have that checked as well if one is already in place. If no GFCI then it is mandatory to install one no matter what the service company does - even if you do the work yourself - you must install a GFCI or replace the defective one. DO not delay this action - electricity and water do not mix well.