Men get boners (or more correctly erections) when they usually see women or if they are gay another man. Women can discharge if they are sexually aroused by looking at a man.
During puberty erections may come at unusual times. Mature men generally only get erections when they are sexually aroused. If a man is homosexual, this arousal will be triggered by other men. It's possible that you, on some level, find other men to be sexually attractive. It's also possible that while you were gazing at a man, your mind was thinking about something sexual, whether related to men or women.