I'm no expert at Java, so this isn't a decisive answer, but I figure it can't hurt to post the code here anyway for others to decipher.
From SpawnerAnimals.java : (Comments mine) private static boolean canCreatureTypeSpawnAtLocation(EnumCreatureType enumcreaturetype, World world, int i, int j, int k) { if(enumcreaturetype.getCreatureMaterial() == Material.water) //
If it's a water creature... { return world.getBlockMaterial(i, j, k).getIsLiquid() && !
world.isBlockNormalCube(i, j + 1, k); //
Make sure it spawns in water } else { return world.isBlockNormalCube(i, j - 1, k) && !
world.isBlockNormalCube(i, j, k) && !
world.getBlockMaterial(i, j, k).getIsLiquid() && !
world.isBlockNormalCube(i, j + 1, k); //
Makes sure the block it's spawning on is opaque, that it's not water, and that there are at least 2 blocks of air overhead. } } It does not appear that it checks whether the mob is spawning underground or not.
Anecdotally, wandering around for a while with an Xray texture pack produced only surface mobs, so I'm not sure what other guards might be put in place to prevent underground spawns.
gaming.stackexchange.com/users/5029/John the Green
Passive mobs will spawn if the following conditions are met:
There is a grass block
There is 2x2x2 empty space
There is a light level above 7
gaming.stackexchange.com/users/18337/Ryan S.
No, they can definitely spawn underground.
I had a world where I had dug out a massive cavern, encasing all the lava in glass, then placed grass on top of the lava to create big underground islands.
I had animals spawning on the grass, at level 13.
Edit: This was, however, in an older version of minecraft.
I won't be able to check to see if that's still true until I get home.
gaming.stackexchange.com/users/15092/SaintWacko
Before they only spawned on chunk generation, I would have them spawn in my grass filled cave all the time, I think they still can, but grass is needed for them to spawn.
gaming.stackexchange.com/users/16560/legacy
According to the Minecraft wiki : no, animals cannot spawn underground.
newly generated chunks will contain mobs...
They will always spawn on the highest available block in a column i.e. the one that can see the sky.
For an animal to spawn on it, this block must be opaque and the two blocks above it must be transparent.
The block does not need to be grass nor does it need to be illuminated (as it does with [Monster] Spawning).
gaming.stackexchange.com/users/64041/The Guy with The Hat
Yes, the passive mobs just need the right conditions.
For Pigs, Cows and Chickens you will need light and grass.
Getting grass deep underground with out an item hack can be a little difficult.
One way would be to dig a hole up to the surface and let natural light strike a block of dirt.
From that block you can then grow more grass and from your field of grass you will get passive mobs.
gaming.stackexchange.com/users/2580/QueueHammer
I beleive they can.
I am playing in 1.7 and I found 3 chickens in my mineshaft.
At first I started to look for a way to get to the over world.
After an hour or so of searching, I gave up and decided to google to see if they could spawn there.
gaming.stackexchange.com/users/67174/Nat
I just found a chicken in my mine, around level 15.
I searched and searched, and there are no entrances to the outside.
The only possibility that I can think of is that there was a 3x3 patch of dirt in the mine, and a nearby lava source which may have exceeded the light requirement.
However, there is obviously no grass around...
gaming.stackexchange.com/users/76616/Conor
I found out that the only passive mob that spawns underground is the bat .
I found this out while reading my Minecraft Essential Handbook , page 38.
Chickens, pigs, cows, and sheep spawn on grass.
gaming.stackexchange.com/users/127996/Jim Jones
There's a rumour that passive mobs (pigs, cows, sheep) can only spawn on the highest solid block. In other words, they won't spawn on grass with a solid block roof over it, such as in an underground cave, a player-built barn, or a glass dome.  Is this true, as of Minecraft 1.0?
Can passive mobs spawn underground?
gaming.stackexchange.com
<minecraft-java-edition>
gaming.stackexchange.com/questions/41432
gaming.stackexchange.com/users/3454/Joe Dovahkiin
They can definitely spawn underground, they just need the right conditions. While a vague topic, it seems that there need to be special conditions in order to make passive mobs to spawn underground.
The community believes that passive mobs can spawn under certain conditions. It is implied that passive mobs can't spawn underground.