Minecraft wiki entry for Spawn, associated text: In Java Edition, the world spawn (the point where players spawn if they have no valid bed spawn) is usually a random (seed determined) point between -500 and +500 on the X and Z axis. If the chosen point is in water (due to nothing but ocean biomes in the -500 to +500 range), a second attempt is made between -1500 to +1500. If this fails due to ocean, the game gives up and puts the world spawn in the middle of the ocean (still at the surface) (attempting to play the flat lands preset Water World does this, for example). Normally, a player who spawns in the water does so near the shore because the world spawn itself picked a spot there.
In Bedrock Edition, an opaque block normally causes all blocks below it to spawn cave mobs, but not if a transparent block is placed on top.