But Prime Kirk likely had other commands before getting the Enterprise. Dehner mentions a 'first command' in "Where No Man..."
Plus, Picard got the Stargazer at twenty-eight.
Neither of those men necessarily had to have the RANK of Captain when they had the position of it. Kirk Prime could have received his first command as a Commander or Lieutenant Commander. Same for Picard. (We saw this happen with Dax on DS9. When she commanded the Defiant
, she was addressed as Captain, yet she was a LCDR by rank.)