It was known that air was a substance which could exert wind pressure and be compressed. Torricelli reasoned that it would have a natural pressure of its own.
He then reasoned that his mercury tube was long enough that the weight of the mercury was greater than the atmospheric pressure, so when he upended it the mercury could no longer be held in and would fall, even if there was no air to replace it.
He tried it, sticking the bottom end in a bowl of mercury to stop air bubbling up round. It fell a bit but then stopped at around 75 cm tall.
If air had been able to get in, then the tube would have emptied steadily. The experimental observation that the level stays permanently around 75 cm is proof in itself that air cannot diffuse through mercury. This answers part of your question.
Having established that the gap could not be filled with air, Torricelli reasoned that there was nothing else it could be filled with either. There was genuinely nothing there, a vacuum. (In practice there is a small amount of mercury vapour, but it is so small as to be insignificant here, and would not be measured for centuries yet. Torricelli's conclusion was correct by the science of the day). This answers the rest of it.
Thus, he could use the height of his dense mercury column to calculate atmospheric pressure. He had invented the mercury barometer.
You can do the same thing with water. But you need a tube of 10 m or more length to get the same weight, because it is so much less dense. And over the following days and months the level will very slowly fall, because air can dissolve in water and diffuse through it.