The fact that Icelandic students still learn Danish in school is tied up with the long history of Icelandic-Danish relations.
Up until Iceland’s independence in 1944, Iceland was a colony of Denmark. In addition to being taught in primary and secondary school, Danish was also the gateway to many higher professions, since studying at the university in Copenhagen was one of the most prestigious educations an upwardly mobile Icelander in the 19th century could get. In fact, Copenhagen was in many ways the centre of Icelandic intellectual life up until the modern era. To this day, many Icelanders choose to attend university in another Nordic nation, such as Norway, Denmark, or Sweden. Because the Nordics are all good places to study and work, there remains an incentive today to develop a baseline proficiency with the language.
Despite its status as a relic of the colonial past, Danish language education still serves some practical and positive purposes today. Written Danish and Norwegian are very similar, and a background in Danish can play a key role in communicating with other Scandinavians. Some have, however, wondered whether Norwegian should instead be taught, as it is more mutually intelligible with Swedish, especially in its spoken form. However, another reason Danish education has stayed in place in Iceland is that Iceland’s neighbours were historically, and continue to be, Danish colonies as well. Specifically, Danish is still taught in Greenland and the Faroe Islands, two territories that have strong historical and cultural ties to Iceland.
This reason is perhaps not front-and-centre in Icelandic education policy, but there is also something to be said for learning a language from a different language group. Norwegian and Icelandic were both West Norse languages, and are therefore more closely related to one another today. Danish and Swedish historically had more contact and influence on one another and are considered East Norse languages. Some argue that learning an East Norse language gives Icelanders the best of both worlds, allowing for communication with both Norwegians and Swedes as well. Note, however, that despite these language groupings, the written forms of the modern Scandinavian language are all more or less mutually intelligible among one another.
Of course, the final reason, like so much in history, is simply force of habit. Languages are useful because other people use them, so it stands to reason that if many scientific, historic, and academic documents were written in Danish, then there is good reason to continue the tradition because it still has some utility.