99% likely it's a 24VAC (output) "doorbell" style of transformer, getting 120VAC input from the light socket that it directly covers.

This could be for doorbell use, or for the automatic garage door opener, or any other (?) low voltage household needs. Heating and cooling equipment also use 24VAC for control wires (thermostats) and the like. Or a furnace humidifier, central vac control wires, ..

Cheers