One very popular view (as espoused by Max Tegmark) is that (quoting count_to_10) :
math works because the universe is based on math
http://www.scientificamerican.com/article/is-the-universe-made-of-math-excerpt/
An alternative view which is more "down to Earth" is that mathematics developed from the attempt to describe the world. This is obvious in the case of Geometry (literally, ' land measurement'). Trigonometry also developed for use in surveying, navigation and astronomy (in the latter case for astrological reasons). Probability was developed to answer questions about gambling.
As Paul T points out, the issue was addressed by Eugene Wigner in a famous essay, "The Unreasonable Effectiveness of Mathematics in the Natural Sciences". http://www.maths.ed.ac.uk/~aar/papers/wigner.pdf
However, the description "unreasonable effectiveness" clashes with the reality of mathematical physics. Take a look inside Landau and Lifschitz. Looking at the horrendous mathematics required to solve many differential equations (Fourier Transforms, Bessel Functions, etc), most of which have no analytical solution anyway, you then might question this description. (I do!) Even more so when you realise that this complex mathematics is still only an approximation of reality.
So in summary my short answer is that :
- mathematics works in physics because it was developed for the purpose of describing the world, and
- it doesn't actually work anywhere near as well as some people make out.