Topical medications are those applied to a body surface, be it skin, eyeballs, or the insides of your lungs. This is usually done to deliver the drug to the particular place requiring repair (e.g. eye drops for an eye infection) while minimizing the amount of drug ending up in other parts of the body where it can cause unwanted (side) effects. Alternatively, a drug may be administered topically but in such a way to ensure it ends up all over (e.g. fentanyl transdermal patches applied to the skin to alleviate severe pain by slowing releasing the drug into the body).
In the case of antibacterial ointments, the gooey greases applied to cuts and scrapes to prevent infection, the drugs they contain differ from those typically given as pills or injections. Ointments such Neosporin or the classic Triple Antibiotic Ointment tend to contain three drugs: neomycin, polymyxin B, and bacitracin. All three were originally isolated from bacteria (bacitracin has a particularly interesting origin story) and act in different ways to harm particular groups of bacteria. Together they form a potent team of bacteria killers.
|Triple Antibiotic Ointment still life (Source)|
However, none of three drugs are commonly used to fight internal infections. There are two major reasons for this. First of all, they aren't particularly adept at making their way into your bloodstream if you ingest them. In other words, they are poorly absorbed from the gastrointestinal tract. Neomycin has instead been fed to people in order to selectively target and kill off a bunch of the bacteria growing inside their guts, essentially an external internal body surface (and so still a sort of topical application).
The second reason for the restricted use of these drugs is their toxicity. All three are toxic to the kidneys if they end up in the bloodstream. Neomycin also tends to cause ear damage and allergic reactions in form of contact dermatitis. Bacitracin also likes to cause allergic reactions (it's up there with penicillin as far as common drug allergies go). Funnily enough, neomycin is pretty good at killing the Gram-negative bacteria usually responsible for kidney-damaging urinary tract infections. It just happens to be a bit overzealous and can hurt the organ it should be helping to protect.
Polymyxin B doesn't like the kidneys or nervous system. However, it looks as though its toxicity might not actually be too severe, so the drug has found some use as a non-topical antibacterial agent in cases where people-infecting bacteria have developed resistance to other drugs.
Leyden JJ, Bartelt NM. 1987. Comparison of topical antibiotic ointments, a wound protectant, and antiseptics for the treatment of human blister wounds contaminated with Staphylococcus aureus. Journal of Family Practice 24(6):601-604.
Powell LW, Hooker JW. 1956. Neomycin nephropathy. Journal of the American Medical Association 160(7):557-560. [First page]
Weinberg ED. 1967. Bacitracin. In: Antibiotics (Eds. Gottlieb D, Shaw PD). Pages 90-101. Springer. [First two pages]
Zavascki AP, Goldani LZ, Li J, Nation RL. 2007. Polymyxin B for the treatment of multidrug-resistant pathogens: A critical review. Journal of Antimicrobial Chemotherapy 60(6):1206-1215. [Full text]