"We have a series of identical pumps, and only the hot ones are foaming. Why is this?"
Initially, this seems contrary to all logic. Higher temperatures will typically lower the viscosity of the oil. Normally, a thinner oil will have a lower tendency to foam because air bubbles will rise out of the oil more rapidly (actually less aeration), and foam bubbles will have a thinner oil wall, which will break more easily.
Foaming is usually caused by:
A contaminant in the oil (another oil or additive, water, airborne contaminant, cleaning solution or detergent)
An oil level that is too high, causing frothing or churning
An oil level that is too low, causing air to get pulled into the suction tube (perhaps from a vortex forming in the reservoir, or the returning oil to the reservoir is splashing onto the surface of the reservoir oil)
An oil temperature that is slightly low (the oil is at the right viscosity to create foam)
Air entering the oil piping on the suction side (upstream, low-pressure side) of the pump
More than likely the oil isn’t foaming because it is hot, but rather the oil is hot because it is foaming. Still, the root cause of the foaming must be determined. Consider that the foam is displacing the oil, and the equipment (bearing, gear, etc.) is being starved of oil and creating the heat.
The root cause of the foam is likely an oil level or contamination issue. Adding more anti-foam additive usually does not work and may make matters worse.
In most cases, an oil change or a partial drain and refill will be necessary. A flush may be required as well if some type of contamination is the root cause. Since this can get expensive for large systems, reconditioning of the lubricant may be considered. However, this does not always work and will probably only be a stay of execution rather than a pardon.
Be sure to resolve the root of the problem before performing a drain and flush. If cross-contamination with another oil is the issue, address the solution with fluid identification (color-coding) and training. Mechanical issues might be due to the tank design, oil return-path geometry or suction-side piping air leaks.
While troubleshooting a foaming problem can be challenging, you should be able to identify and correct the root cause through a process of elimination.
Read more on best practices for lubricants: