In certain fairly common situations, the game spawns mobs in caves at any depth as surface mobs and counts them toward the surface density cap. This can leads to fewer surface mobs and more cave mobs being spawned than intended, unbalancing the game. I have attached a world save file, "Surface & cave spawns.mcworld", that demonstrates this.
The world has 3 locations you will use: A Spawn Room, a Testing Room, and the Surface. Command blocks are provided to teleport you between these locations.
The world is designed so that only monsters can spawn in it, and only on the spawn floor. (Technically, bats, slimes, and wandering traders can also spawne, but they're immediately killed by repeating command blocks.)
You spawn on the surface in front of a blue square centered in a yellow ring and, farther out, a purple ring. The spawn floor is at Y=6 below the blue square; it is one chunk in size. The purple ring encloses the density cap measurement area for spawns on the spawn floor; it is 9 x 9 chunks in size. The yellow ring encloses the area you need to stay within to prevent mobs from spawning outside the density cap area.
Except for the Spawn Room and the Testing Room, which are mobproofed, the density cap area is entirely filled with stone. This ensures that only monsters can spawn during the test and they can only spawn on the spawn floor. It also ensures that there are no unknown monsters taking up part of the density cap.
The Testing Room is at Y=30, just outside the spawn floor chunk. It's like an AFK room in that when the player is within it, all blocks of the spawn floor are within spawning range The Testing Room also has a lever that controls the "mobspawning" game rule, and a repeating command block that every 10 seconds reports what mobs are present on the spawn floor.
Steps to reproduce:
1. Open the attached world Surface & cave spawns.mcworld.
2. Press the button to teleport to the Spawn Room. Verify that there are no mobs on the spawn floor or in the mob holding pen. If there are, use the Kill All Mobs button to get rid of them.)
3. Go to the Testing Room and flip the lever to enable mob spawning. A repeating command block will start outputing a list every 10 seconds of any mobs found on the spawn floor. Wait until 8 mobs are listed; it should take less than 5 minutes. (The density cap for hostile mobs is 8, so no more will spawn if you wait longer.)
4. Disable mob spawning.
5. Go to the Spawn Room. You should see 8 mobs on the spawn floor. Use the button to teleport them to the holding pen. (Note that the pen is outside the spawn floor chunk, but still inside its density cap area.)
6. Go to the surface.
7. Place a stair, bottom slab, or leaves in front of the bottommost observer. Command blocks will replicate your block over the entire chunk, so that every block of the spawn floor has your block on the surface above it.
8. Return to the Testing Room and enable mob spawning again. Wait a few minutes to see if any monsters spawn.
Since the mob density cap is filled by the monsters in the holding pen, no more monsters spawn.
More monsters spawn, up to 8 of them if you wait long enough. What's happening is that the first set of 8 monsters were tagged as cave spawns and were counted under the cave density cap, which was filled to capacity. However, placing the blocks on the surface allowed another set of 8 monsters to be spawned and tagged as surface spawns. This can be verified by checking the Surface property of the entity for each mob.
Stairs, bottom slabs, and leaves are not the only blocks that cause cave spawns to become surface spawns. So far, other blocks I've identified that this do this include Farmland, Grass Path, Lantern, Chest, Cactus, Turtle Eggs, and Lectern. (Note that slabs are a special case: Top slabs do not cause surface spawns, only bottom slabs.)
It's particularly noteworthy that this bug will always cause spawns under farmland, village paths, trees, and platforms made of bottom slabs on the ground, no matter how deep the cave is. My experiments tell me that all that's required is to have an unbroken column of solid blocks, topped by one of the triggering transparent blocks, above the spawn block. As the demo world shows, this can cause surface spawns to occur at any depth, which can reduce the number of monsters spawning on the actual surface as well as increase the number of mobs found in caves.