Giraffes don't need to drink water because they already get some from the leaves they eat. However, when they do drink water, they can drink several gallons at a time.
That is bad because a giraffe has to bend down and get into a vulnerable position when drinking.
I believe that refers to the act of a giraffe drinking several gallons of water at a time. It's not that drinking itself makes them vulnerable, it's that drinking for a long period of time makes them vulnerable. The main part of the sentence is they can drink several gallons at a time, and it's what's closest to that. I think it's natural to infer that that normally refers to the main expression closest to it, especially when it makes sense logically.