Do you have to ground a transformer?

In most cases the enclosure of the transformer is grounded for safety reasons. However, a transformer will function properly without being grounded. Be sure to research all grounding requirements for your specific application against the NEC (National Electrical Code) as well as any local electrical codes.