An infection that is acquired while admitted to a hospital is called a nosocomial infection. These infections are secondary, meaning you are admitted to the hospital for problem A, and while staying in the hospital, you develop problem B. Nosocomial infections are a huge concern in hospitals, especially when patients are already immunocompromised. Nosocomial infections are common because hospitals are full of pathogens, making them breeding grounds for some awful infections. What else would you expect from none other than a hospital: the one place where all the sick people congregate, bringing all major pathogens into one central location. Hospital infections are mostly commonly acquired through inhalation, through equipment use and inoculations, and through ingestion. For example: the most common source of pneumonia is from the use of the endoscope tube. Yikes!
As a result of nosocomial infections, hospitals have made infection control teams, who are responsible for monitoring infection outbreaks in patients. This team is also responsible for implementing infection prevention measures and for monitoring the health of hospital staff.
(Note: the image above is a web of factors that determine whether or not a patient may acquire a particular infection; it was taken from my Microbiology lecture notes).