If skin is intact (there are no cuts, for example), there is no risk of HIV transmission from casual HIV contact such as shaking hands, hugging, and kissing on the cheek. Intact skin is an excellent barrier. HIV is transmitted only via potentially infected secretions such as blood, semen, vaginal secretions, and breast milk.
Nurses are not just told to wear gloves when dealing with HIV patients... they're told to wear them all the time. This is because nurses and other healthcare providers often come into contact with bodily fluids unexpectedly; it's impossible to say when they will and when they won't. Wearing gloves helps to reduce individuals' risk of exposure to bacteria or viruses that can be transmitted by touch; it also helps keep them from spreading such bugs from patient to patient, or from self to patient. Gloves are always changed between patients to help reduce the transmission of diseases from one patient to another. In addition, washing the hands with soap and using alcohol-based sanitizing gels are other ways that nurses and other medical personnel protect patients.
As for prison guards, hand-to-hand combat can cause a lot of damage. Wearing gloves helps to reduce the risk of accidental exposure to infected blood -- a fluid that's a known HIV risk and can also transmit other diseases.

