It is commonly seen in older dogs who then develop cancerous tumors.

Developing (or not developing) a tumor is not caused by a prior infection.

What could be said is that if undiagnosed cancer is present the immune system is very likely to be suppressed in geriatric dogs, which can lead to serious and repeated unexpected infections. In another words the presence of undiagnosed cancer can cause bacterial infections, but not the other way around. Of course cancer need not be involved as aging alone results in an immune system that is less responsive to disease, where opportunistic bacterial infections can arise.