I mean in most cases a mathematician is not going around and checking each and every case, why would software do that?
Formal verification a la cocq/Agda/lean works by constructive logic. (Disregard the middle paragraphs, I'm sure I'm not telling you anything new)
The type system is strong enough to encode various statements, even about variables (dependent type system, this is a valid type: a + b == b + a)
The only way to create an instance for this type is by proving the statement. The == type can only be created by trivially equal expressions, so it will accept a == a. So in the definition of the above you will go step by step, each step itself being accepted by the compiler, and at the end you get a proof and a compiling program, a bit similarly to how you would do it on paper.
So I guess it boils down to. Could a mathematician figure out some elegant proof for the system that somehow makes "checking each state" reduced to an easier statement? If yes, then formal verification can also do so. If no, then LLMs may be able to scale up what is feasibly provable, but there is no real alternative. Real world testing is just scratching the surface of the state space.
All in all, that's why it's paramount that systems are designed with complexity in mind. We can compose simple function into a simple function and have it explode in complexity, but it's also possible to choose good primitives that are easy to "mock out" (often both in practice and theory) and not significantly increase the whole system's complexity.