Coaches and personal preferences affect such choices. Some are positional players (Karpov). Others who have attacking styles go for sharp openings and sharp lines (Kasparov, Polgar). Some players have very diverse repertoires, others play fewer openings but know them inside out. It's a matter of personal preferences and tournament experiences. The influence of a coach might be significant as is his/her own preferences. At pro level players now prefer very reliable and solid openings. So, the King's gambit or Albin Countergambit is almost never played with some rare exceptions where they were used more like a surprise value and boosted with modern engine analysis.
At amateur/club level, especially in blitz games, gambits are still popular including some gambits from semi-open games which also became popular (like the Morra Gambit) at this level. Amateurs might have haphazard opening repertoires. At more serious level, coaches help establish the repertoire and show ideas and plans that can be used. It's still going to be tied to some preferences of a given coach and his/her own experiences, ideas and styles of play.
Mark Dvoretsky (author of chess textbooks) described a situation when a player was influenced too much by his coach and played the sharp King's Indian Defense and Sicilian. Dvoretsky advised changing the style to the player's less aggressive personal preferences of play which is said to have helped a lot. Dvoretsky argues that players have to have their opening repertoire tweaked to their style of play and personal preferences.
At amateur level, open games are often recommended as the opening repertoire. Pandolfini advised that, for example, and published an opening textbook for amateurs (or young aspiring talents who just start out) that focuses only on e4. Some may recommend d4 from the get go. For example, the London System might be good for a beginner. Nakamura's video where he teaches it to a beginner (blogger Pokimane) went viral on YouTube.
Undoubtedly sometimes players do explore various openings and try out stuff they usually don't play. A player may introduce changes to his/her opening repertoire. It's all tied to the player's level. If an early coach had too much influence or the player has too narrow a repertoire, I guess, the player's repertoire might come from his/her childhood but such reasoning is somewhat speculative. It's a whole different story to explore as to how opening repertoires might change over time depending on various players and how much stuff is there from childhood.
Overall, it's a mix of various factors: personal preferences, experiences, recommendations and influences of coaches. The proportion of such factors varies from player to player.