To add to Denis de Bernady's excellent answer, it's also the same reason Google spends money on giving people free search, free email, and free WiFi. It's not out of the goodness of their hearts, it's because the more people using Internet, the better off Google's business model (advertizing) works.
Similarly, USA benefits when more people worldwide engage in commerce and spend money and economies everywhere grow (since that growth feeds both US originated investments in those countries, AND US companies' sales to those countries). And the more that happens, the better for both US economy AND US Treasury. (there's many different economic mechanisms involved, but the sum total is that there's benefit to US when economies grow and are healthy and detriment when they shrink and downturned.
And as AIDS clearly has a net detrimental effect on economy (both direct, as people spend money taking care of those who are sick, and indirect, by reducing available actors in the economy), fighting AIDS has an additional benefit of reducing that negative effect.
Think of it as following similar underlying logic to Marshall Plan at the end of WWII (but without "strengthen Western Europe against USSR" component).