All the pollution generated inside factory buildings is moved outside. To see that, just enable the pollution overlay inside a factory building, you'll see that all the red periodically disappears.
To see for yourself that all the pollution moves outside, you could try building the same pollution-heavy setup twice, once in the overworld and once in a factory building, then start them at the same time and check on the overworld map how much pollution each setup produces.
If a factory building is picked up, then the pollution produced inside it (as long as the machines inside can still run before the internal power supply runs out) will slowly accumulate, then get released all at once once you place the factory building back down.