Well, first of all, they are not different languages, they are different dialects of the same language. (Well, admittedly there are some tiny pockets of Frisian, which is a distinct language, in the northwest, and the languages of Switzerland and Luxembourg are sometimes considered German dialects, sometimes distinct languages.)
Second of all, the dialect borders are not generally the same as the state borders.
Partly, the relatively rich landscape of dialects stems from the fact that national unification came rather late to Germany (in 1870), and even after that, for most of its history, Germany has had strong federalist structures rather than one dominant political/cultural center influencing the language.
Having said that, nowadays there is a strong mainstreaming of the dialects towards Standard German, mostly due to the fact that Standard German is used almost exclusively in the media, and in virtually all written materials. The Plattdeutsch dialect in the north, for example, is dying out quickly.
Also, most Germans will be able to switch to Standard German without hesitation if you ask them to.