system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: Why do some animals, like sea turtles and salmon, lay eggs away from their natural habitat?

This might be a strange question, but why do sea turtles lay eggs on land and not for example dig up holes inside the ocean? They live their whole lives in the ocean, so why do they lay eggs on land? Why travel so far just to lay eggs?

Same goes for some salmon, why do they leave the oceans and lakes, and go upstream on rivers and not lay their eggs where they live? 

It is probably something to do with protecting their offspring, but it seems to me that they still have predators that hunt their offspring fairly easily where they hatch/lay their eggs, so maybe there is another reason as well?
gpt
Turtles breath air, and the embryos in the eggs must get their air through the membrane of the egg which they wouldn't be able to under water. Also, the right temperatures for the eggs don't exist in the water.

Salmon are incapable of living in salt water when they are first born, so the eggs must be laid in fresh water. Going back to the same place they spawned makes sense: it's a known quantity capable of supporting salmon eggs.

So the general reason behind both is that these are creatures that have adapted to live in environments as adults that they could not survive in as newborns, so it is necessary to return to the place (or a similar place) to that in which they themselves were born.