Despite the enormous densities, the early universe didn’t collapse into a black hole because, simply put, there was nothing to collapse into.
It’s relatively straightforward to make black hole if you are persistent enough. All you need to do is apply enough pressure and keep squeezing something down to incredibly small volumes. At some point below a critical threshold the gravitational force becomes so strong that it overwhelms any other force of nature, creating a black hole. If we were to take you and squeeze you down to about the size of an atomic nucleus, you would become a black hole with the width of an atomic nucleus and the mass of a human being. We could repeat the process with the Earth, creating an Earth-mass black hole about the size of a bean.
The key to making black holes is density. You need an incredibly high density to trigger a sufficient amount of gravitational force. And while the universe in its present day is not dense at all, with an average density of about one hydrogen atom per cubic meter, and its early days things were much different.
Billions of years ago our universe was a lot smaller than it is today, and that means its density was much higher. So it’s natural to wonder why the universe didn’t collapse directly into a black hole.
But to make a black hole it’s not just a matter of density, it’s a matter of density difference. In order to feel the gravitational force you need a difference in density from place to place. If the amount of matter is smooth throughout a volume and there are no differences, there will be no net gravitational force pulling in any direction. In order to make a black hole you have to take a bunch of matter and squeeze it down into a very small volume, and crucially leave a bunch of empty space surrounding it. That way the gravitational force can act and a black hole can form.
Even though the early universe was incredibly dense, it was also incredibly uniform. The average density throughout the universe was the same from place to place. There weren’t enough differences to trigger the formation of black holes.
But what about the entire universe itself? Surely with all that matter in the universe it could have halted the big bang in its tracks and collapsed everything down back into singularity. This wouldn’t strictly be the formation of a black hole, however. Black holes are points of infinite density sitting inside of space. The singularity at the big bang was an infinite concentration of space itself.
But either way, this didn’t happen because the universe was also dynamic in its early days. It was evolving. It was changing. And most importantly it was expanding. The expansion of the universe in its early days prevented all the matter from collapsing. Sure, if our universe was born with way too much matter it could have slowed down that expansion. But the fact is that there wasn’t enough matter to do so, and the expansion of the universe was able to dilute the material of the cosmos enough so that it could never collapse again.