I think that there is a different point of view that's not being considered here, but it's difficult to know for sure with the little detail that you provided in your question. It seems very unusual and unlikely that HR would have a policy that prohibits something as simple as a visit to a co-worker in the hospital. Obviously, I'm basing this off of my experience living and working in the United States, other cultures may have different norms for this type of behavior. So you need to respect the norms and work culture where you are. But ultimately this sounds to me as if the person you visited may have been uncomfortable with your visit and reached out to HR or their supervisor. Perhaps they are embarrassed, or uncomfortable with interacting with you outside of the office for something that they consider be a very personal and private matter.