It's within the law for EMS to disclose to the prison staff "He's having a heart attack. We need to move him to a hospital to try to save his life." That would meet the minimum necessary standard to get the patient the care he needs. That disclosure is necessary to get him released from prison so he can be transported to the hospital.
However, if an EMS person was friends with one of the guards and spent a minute or two basically gossiping about the case to one of the guards as a form of socializing, that has nothing to do with getting the patient the care he needs and would be potentially a firing offense.
There shouldn't be a loophole because the guards should be covered by other rules. They just wouldn't be covered by HIPAA per se.
The fact that HIPAA doesn't apply to the guards doesn't mean the guards can do whatever they want. It just means that you would have to discipline them under a different rule or law.
(IANAL. This is not legal advice. It's just my best understanding of HIPAA having worked for an insurance company for a few years, during which time I received annual training for HIPAA.)
"Hey, we as medical professionals can't disclose your health info. But we have to keep these guards around for safety, who will hear everything, and they can say all they want!"