There are many reasons why any given captain would be the best fit for a ship and mission. A former astrophysics officer, now in the chain of command, would be a good captain for a science ship studying stellar phenomena. A captain with multiple first contacts under their belts at whatever rank would be a good fit for a diplomatic ship. A battle veteran would be a good captain to have in a lawless/border area, even if the mission isn't specifically peacekeeping.
That said, any captain can rise to the occasion or fall short, despite seemingly being ill or well-suited on paper.
That said, any captain can rise to the occasion or fall short, despite seemingly being ill or well-suited on paper.