Why do they speak German in Austria and not some other language?
Well, to be fair, they don't exactly speak the same German language as spoken in Germany. Austria has a relatively distinct dialect of German with its own vocabulary as well as a few variations in Grammar and pronunciation. It's not as different as the German spoken in Switzerland, however.
Austria also has different minorities who speak different languages as their native tongues. These languages include Turkish, Croatian, Serbian, Hungarian, and Slovene. In total, about 90-95% of Austrians speak the Austrian dialect of German as their mother tongue. The rest do speak it as a second language, however.
Check out this video which illustrates some of the differences between Standard German and the German spoken in Austria.
But why is Austria a (primarily) German-speaking country today?
The word "German" used to only refer to someone who spoke the German language or who was "of the German people". While different historical states, nations, empires, and federations included the word "German" in their official names, they all consisted of "groupings" of German regions and peoples and not of unified "nations".
German people weren't "German nationals" as such, but scattered groups of people who spoke German. These people have lived in the region of Austria since the middle ages.
So the "German people" used to be the people who lived in the modern-day regions of Austria, Switzerland, Lichtenstein, Luxembourg, Belgium, Germany, and so on, who spoke German.
Today, with the distinction of the German nation, it would be confusing (and wrong) to call everyone who speaks German "a German" in the same way that it would be wrong to call everyone who speaks English "an Englishman".
(As a side-note, there's a tendency to call all Arabic-speaking peoples "Arabs" which must be an exception to the general rule.)
So German is the official language of Austria because Austrians were a part of the German-speaking world long before the word "German" had anything to do with nationality.
How Come Austria Didn't End Up Speaking Hungarian Or Some Other Language?
Austria was part of the Austro-Hungarian Empire from 1867 to 1915. This empire was a political unification of different nations. Its goal was to create a political and military unison under one single administration, but not necessarily for member-states to assimilate into one culture or language.
It's also worth noticing that German was the lingua franca in the Austro-Hungarian empire, not Hungarian, meaning that if a Croat, an Austrian, and a Hungarian were to have a conversation, it would probably be in German.
Other languages have equally been spoken in Austria and some might have threatened German as the common language spoken at some point.
It's a known fact, that the Ottoman Empire ended their expansion after seeing defeat in front of the gates of Vienna in 1683. Perhaps, if the Ottomans had won, Austria would be a Turkish-speaking, Muslim nation today? Maybe even more European countries would eventually have been invaded too.
These are all speculations, however, and to this date, Austria remains a German-speaking country.
And that's probably not going to change any time soon!