Sweat glands in mammals are primarily related to thermoregulation. They help regulate body temperature by producing sweat, which evaporates from the skin surface, cooling the body. This process aids in maintaining a stable internal temperature during physical exertion or exposure to heat.