These are required to connect the PVC pipe from the back of the light Frame (Niche), and green #8 copper bonding cable ran from the inside of the light Frame (Niche). This installation is always underground and required to be at least 18 inches deep by the National Electrical Code and all Cities in the USA. Then the PVC pipe is turned up above ground usually in a location away from the pool so it is not easy to see. The junction box must be at least eight (8) inches above the water level of the pool.
The reason for this is because the PVC pipe holding the light cord and green #8 copper bonding cable is filled with pool water for the life of the pool. The light cords and #8 green copper bonding cable are approved for this wet installation. Movement of the water from people jumping into the pool or swimming causing waves or fluctuations of water levels. These fluctuations push water several inches up and down the PVC pipe installation leading up to the Swimming Pool/Spa Light Junction Box. Eight inches in height keeps any water from ever reaching the pool light cord connections, electrical cable connections or #8 green copper bonding cable connection. From this Pool/Spa Light Junction Box, all cables supplying the lighting circuits are then run in separate and completely dry PVC pipes to the controller location.
Keep in mind that most applications are for pools and spas with 1-2 light and require only one specialty junction box. This particular photo shows many Pool/Spa Light Junction Boxes for a pool in Highland Park that had 12 lights. The other photo is of an old Pool/Spa Light Junction Box used years ago before the new ones were required by the National Electrical Code. From the photo you can see why.