Gendry knows the queen wants him.
When the Red Cloaks (or was it Gold Cloaks) catch up with Yoren's bunch, Gendry knows they are after him (the Lannister captain and Yoren both make this clear).
I assume (big assumption, because Gendry is not the smartest guy) that Gendry knows from his mother and from the events of his life that his father was of the nobility of Westeros.
But then again, Gendry may be smart enough to know (assuming his mother told him his real identity) that feigned ignorance is his best defence... this means he lied to Jon Arryn, Ned, Arya, and everyone about his identity... and then again this theory assumes that Gendry only talked about ringing Bella's, the barmaid at The Peach, bells because he knew she was his sister.
I think that joining Beric's King's Men appealed to Gendry's desire to spite Cersei.
Folks, I don't know that even if Stannis never has a son by Selyse and if Shireen dies that Gendry would ever be the lawful heir to the Baratheons. He is a *******. He was never legitimized by Robert and the Lannisters will never do it for him. If some Baratheon loyalists wanted to support Gendry, they could, but Edric would be a more logical choice since his mother was a noble and he was raised as a noble. I don't think that primogeniture works with bastards. By the way, Dorne could always support Mya or Bella.
Stannis is indeed a self righteous, inflexible jerk, but if he wanted the Baratheon name to live on he could adopt and legitimize Edric Storm... or even Devan Seaworth for that matter.