Welcome to AA!!! I am afraid your simple question requires a complex answer but Ill try to keep explanation easy. Basically, bacteria are everywhere- everything you touch, breath or consume. The majority of the bacteria that exist are not harmful despite what the zillions of hand/surface disinfectant commercials would have you believe.
In aquariums, there are 'good' bacteria that consume ammonia & nitrites & convert them to nitrates. Likewise, there are 'good' bacteria that live within most species intestinal tracts (humans & fish alike) that aid with digestion. Quite a large number bacteria are harmless unless something throws the natural balance off. A healthy fish with a good immune system can fight off most 'bad' bacteria as can a healthy human. An example is staph bacteria- they exist naturally on our skin but if they enter our bloodstream, it can be potentially fatal. Similarly, a simple scrape for most of us is no big deal but for an immune-suppressed person, it can be fatal.
A healthy aquarium with a working nitrogen cycle and regular water changes provides the best environment for healthy fish along with a good diet. Strong , healthy immune systems are the best defense against 'bad' bacteria for both fish & humans and will prevent the likelyhood of diseases related to 'bad' bacteria. Not sure if this helps answer your question but its the simplest answer I can offer!