Eugene Wigner posed this question eloquently in his 1960 article, “The Unreasonable Effectiveness of Mathematics in the Natural Sciences”. (An imperfect transcription is available here.)
The miracle of the appropriateness of the language of mathematics for the formulation of the laws of physics is a wonderful gift which we neither understand nor deserve. We should be grateful for it and hope that it will remain valid in future research and that it will extend, for better or for worse, to our pleasure, even though perhaps also to our bafflement, to wide branches of learning.
And there’s no obvious reason to expect that this would be the case. Many sciences are, paraphrasing Richard Feynman, not about “how does it work?” but “how did it get that way?”. For example, geology and biology are not based upon mathematical laws but rather figuring out how things developed over long expanses of time when they could have come out entirely differently due to small changes along the long history.
Even in astronomy, sky watchers from the ancients through Kepler tried to figure out mathematical laws that would explain the configuration of the solar system. Now we know that the sizes and orbits of the planets are just how the game of cosmic billiard balls happened to end up here, and that other solar systems, based on knowledge of thousands of exoplanets, can be and are radically different. There’s no mathematical law that explains the size, composition, and orbit of Earth’s Moon. It’s as it is because the young Earth got whacked by a Mars-sized planetoid and the debris condensed into the Moon. Make a tiny change to the planetoid’s orbit and there would be no Moon or an entirely different one.
This makes the “unreasonable effectiveness” of mathematics in the “how does it work?” sciences even more of a mystery.
In Our Mathematical Universe, Max Tegmark suggests that mathematics describes the fundamentals of the universe so well because the universe is essentially made of mathematics and goes further to ask whether the multiverse may contain realities built upon other kinds of mathematics than our own.
Of course, if the simulation hypothesis is correct and we’re living in a computer simulation, we should expect it to follow simple, predictable rules that a computer can execute.
And the entire scientific and engineering field of fluid mechanics is based upon models (the Navier-Stokes equations) which entirely ignore the molecular structure of liquids and gases and the electromagnetic interactions among their molecules which are responsible for all of the phenomena it studies. This is an example of an effective theory, which is useful to study and predict behaviour of systems under certain conditions, but makes no claim to be fundamental and will break down beyond its limit of validity.
Some physicists believe our so-called fundamental theories such as the standard model of particle physics and general relativity are effective theories that describe the low-energy behaviour of something else which may be much simpler that underlies it all. Stephen Wolfram’s Wolfram Physics Project is one effort to find such a lower-level fundamental theory that might explain things we now consider as “just the way things are” such as why there are three dimensions of space.