A compressor in a window AC unit works by circulating refrigerant between the indoor and outdoor units, absorbing warm air from inside the garage and releasing it outside, resulting in cool air inside the garage.