Prestige for powerplay.
There are a few reasons for what played out:
Germany wanted Morocco for itself as a colony. They did want exactly that patch of land, for business interests, resources, and more so for a base to interfere with British shipping, etc.
But that was a faint and weak reason. Not in the least because French influence was by then too strong in Morocco, as they made their moves already from 1904 onward and any prospects to snatch it from French influence exceedingly remote after the first crisis.
More important at the time was indeed the calculation to separate the French from British and thus to re-order the power structure in Europe, on the continent.
But as that already failed during the first Morocco crisis, a more realistic contingency was drawn up. As a third option foreign affairs state secratary Alfred von Kiderlen-Wächter envisioned to threaten interference against French interests in Morocco, just like a few years prior, but already offering a deal to 'not do it': "we let you have Morocco but in exchange we'd like all of your Kongo territory."
The long term goal for this territorial gain was connecting German colonies in Cameroon and East-Africa, dividing the British African colonial empire in two, separated by an entirely German-controlled stretch of land.
For two weeks this was an informal proposal and when the German government repeated this proposal to the French government offcially to increase the pressure.
This concrete territorial gain – which then turned out to be much smaller than originally demanded – was however still not the end of it.
The biggest reason was to demonstrate and gain prestige. On the international scene diplomatically: primarily showing French, British, that they would be willing to fight for their 'rights', equally of course to the Austrian-Hungarian allies. But also internally: triumphant foreign policy makes nationalists proud, and follows suit to the clamoring demands of those who argued for increased colonialism and world power. As evidenced by the saying uttered by Kiderlen-Wächter when Wilhelm ordered the Panther to Agadir: "Finally an act, a liberating act…"
All this combined with the declared intent to not needing a war in Europe, sending war ships to the actual zone the conflict is about was seen as less agressive, and indeed almost reasonable.
But after exposing yourself by making these steep demands towards France, arguing that they would be fully justified, getting just a "Non!" and nothing else in return would weaken that diplomatic prestige substantially.
(To quote @Mark C. Wallace: "In international relations of the period, "right" was synonymous with "might" And not gaining territory after making such a scene would mean the Germans were 'not right')
As the 'compensation' Germany did receive was just a fraction of the initial demand it achieved successfully two things at once: getting further isolated antagonising France and Britain, and also putting more pressure into the kettle of internal aggressive and expansionist policy actors that wanted war, since the German public saw the whole affair diametrically different than those in France and Britain: as a giant slap in the face and humiliating. Editorials and the parliamentary majority were disappointed at the German Reich loosing honour and preferred to go to war over all that anyway.
Q Why did Germany request compensation after the Agadir (2nd Moroccan) crisis? –– But why should Germany get compensation from France for sending troops to Morocco? To me, it seems like Morocco is completely unrelated to Germany. I mean, couldn't they have just sent a whole fleet of battleships over to France directly and demand compensation that way?
Strictly speaking German demands were laid out before and during the crisis. And those demands were always directed at French 'possessions' in Africa.
That was exactly the point. Gaining something anywhere, re-ordering power in Europe indirectly, without risking war in Europe. 'Sending a fleet to France' would have meant immediate war, and at the time already with the alliances largely in place as they fought a few years later. Sending a gunboat to the conflict zone was 'protecting your interests', at least outwardly, while sending your fleet to the homelan was anything from plain blackmail to declaration of war.
"As in other cases of Wilhelmine world politics, prestige took precedence over interest in the second Morocco crisis. Germany was economically much stronger than France. Unlike its neighbour to the left of the Rhine, it did not need colonies and protectorates to cope with the trauma of defeat and the subsequent loss of territories. Germany set out to outperform England economically. But all this was not enough for the political right. Germany was to rise from the great power it had long been to the leading world power: Since the Morocco crisis of 1911, there was nothing more to be interpreted.
–– Heinrich August Winkler: "Der lange Weg nach Westen: Deutsche Geschichte vom Ende des Alten Reiches bis zum Untergang der Weimarer Republik, Volume 1", CH Beck: Düsseldorf, 2000. (p314)
–– Emily Oncken: "Panthersprung nach Agadir. Die deutsche Politik während der Zweiten Marokkokrise 1911", Droste: Düsseldorf, 1981.
–– Thomas Meyer: "Endlich eine Tat, eine befreiende Tat…: Alfred von Kiderlen-Wächters 'Panthersprung nach Agadir' unter dem Druck der öffentlichen Meinung", (Historische Studien 448), Matthiesen: Düsseldorf, 1996.