Java Edition players can type “/gamerule doMobSpawning false” into the chat bar to disable mobs. You'll need to be a server admin and have cheats enabled. Keep in mind using this setting will also disable friendly spawns as well, like animals.
Do mobs spawn randomly?
Not only do mobs spawn randomly, but there are mob spawners in the game, often in dungeons and abandoned mineshafts; they cause a specific type of mob to spawn.
What does turning off mob spawning do?
Disabling mob spawning in Minecraft stops all mobs from spawning into the world.