Pokémon, generally Legendaries, are shiny-locked primarily to reserve inherent value behind them to then use in distributions and events. When a Pokémon can't be obtained as a shiny through regular means, it gives that Pokémon the opportunity to be a shiny in an event tied to a promotion, or a later game with a new method of encountering them (Reshiram/Zekrom in ORAS or Solgaleo/Lunala in the SwSh DLC). There's no denying there's a community that this appeals to, acting as a selling factor for them. For instance, though it still would've been successful, I'm sure not as many players would participate in the Shiny Treasures of Ruin Raids, or as many people would care for completing the BDSP Pokedex, if it meant they didn't get exclusive, or near enough, shinies.
For Pokémon that can be obtained through other means, it's likely up to cutscene continuity, as the previous answer said. It'd be less of a hassle to just shiny-lock the Pokémon than decide when they should be determined shiny, as Pokémon like the starters, titans, etc appear in cutscenes before they're obtained. I don't think there's much of a reason for Gift Pokémon this doesn't apply to, beyond Game Freak deciding it to be this way.