The CDC does not recommend requiring consent before testing:
https://www.cdc.gov/hiv/policies/law/states/testing.html
but each state has its own rules.
Since HIV is now very treatable, and that heterosexuals are vulnerable, as well as less of a stigma associated the being gay, may doctors do order it as a part of a general physical. In any event, it would be ethically and legally wrong to divulge the result to a third party without the patient's consent. Federal privacy laws (HIPPA) protects that. Mandatory testing should only be required of those whose jobs would put the public at risk (those are few and far between. Many support mandatory testing before marriage, as syphilis testing is in many states.