I don't think it was really a secret anyway, but he did it in order to inspire someone else.
This season's contestant, Bobby Saleem, was really struggling with how to tell his father that he was gay. Bob decided to show his support in the most awesome of ways. He said in a confessional for the episode that he had never discussed his sexuality on the show, but felt like this was the right time because he wanted to show Bobby that he didn't have to live in shame. Then he told him this:
“I’m gay. I knew a very long time ago that I was gay. I think that when I came out, when I was 17 years old. It was one of those kind of things where I realized there were so many
obstacles, but being gay doesn’t mean being weak. Being gay doesn’t mean that
you are less than anybody else. It’s just who you are.”
After the show, Bob tweeted this to his fans:
“THANK YOU to everyone that supported my decision to talk about being
gay w/Bobby. I felt like it was appropriate & necessary. LOVE
Bob Harper is the second trainer from the show to come out publicly (Jillian Micheals being the first).