Question is straightforward: Why is part of Daniel written in Hebrew but a middle section written in Aramaic?
There are a whole host of explanations that have been proffered. Most of this answer is based on this book which summarises the consensus opinion that the first six chapters and the remaining ones constitute two separate sections (textually that isn't difficult to see, the first section is narrative and the second visionary, they also run chronologically parallel). This of course is almost the basis for an answer to the question - since this dissection is almost in line with the language shift - save the first chapter (which "should" be in Aramaic) and the seventh (which "should" be in Hebrew).
It seems entirely plausible that the first section was composed in Babylon and the second in Israel. This would lend to the explanation that the first chapter's Hebrew is merely introductory (similar to the rest of the more historical accounts of the Bible), while the seventh's Aramaic remains problematic. There is a lovely textual/narrative symmetry that links chapters 2-7 in pairs (2 and 7, 3 and 6, 4 and 5) which would then tie the seventh chapter in some way to the first section, making its Aramaic an understandable choice.
Further opinions speculate simply that the entire book was originally written in Hebrew, but lost, and only the Aramaic translations (which were and still are prevalent because Aramaic was widely spoken) of some sections were preserved. Others speculate precisely the opposite - the entirety was written in Aramaic (being the more universal and diplomatic language of the time) but in order to canonise the book they needed to translate at least some sections to Hebrew. Which chapters to translate could still be explained as above. Still others propose an explanation that is seen in certain parts of Jewish dogma from the same period - that the Aramaic was for the layperson and the Hebrew was for the more academic/elite. This makes a lot of sense in light of the narrative/visionary breakdown.
Another explanation for chapter seven's diversion from the Hebrew of the rest of the section is that it's a connecting link - being contently more like the second section, but in the language of the first.
The simplest explanation is simply redaction. The two languages are a natural result of the bilingual region.
For the last portion of the book there is a frame of sealing. The prophecies were to become relevant for the future after the time in Babylon, when the people would have long settled back in their land and speak their language, Hebrew.
For Daniel Hebrew was not just his mother-tongue, the language of his youth, it was the language of a chosen people. At his old age he still turned towards Jerusalem when he prayed to God. He loved, studied and knew the Law and the Prophets. In his decisions as an official under different kings he had very certainly often relied on Mosaic regulations (which had proven successful to him from young age on).
If he in Babylon in a a foreign environment had retained his Hebrew, those returning to their promised home land could and should regain it, if it should have been lost.
This is the frame of sealed prophecy spanning over the visions of chapers 8 to 12:
'The vision ... that was told to you is correct. But you should seal up the vision, for it refers to a time many days from now.' - Daniel 8:26
'He said, "Go, Daniel. For these matters are closed and sealed until the time of the end.' - 12:29
To write this last part of the book (which really was a collection of documents) in Hebrew would be just natural. With regard to the sealing of these contents it seems more than indicated not to use the Aramaic.
For the first part to be in Hebrew the most likely reason is that there was no written account of these first three years of Daniel's education in Babylon. The beginning of chapter 2 is an introductory link to what was the beginning of Daniel's career as an official of high rank of the Babylonian court. Verses 4b to 11 of chapter 2 (the beginning of the Aramaic text may have been part of a royal protocol and decree (in Aramaic) which followed the reported event.
To continue in Aramaic may (in addition to the fact that the now surrounding and officially used language was Aramaic) be interpreted as Daniel's signal to his fellow countrymen that God's decree for those living in Babylon was to settle and work for the good of the city (which obviously would not mean to shun and despise the language spoken there).
Daniel may have written the first part of the book as an introduction to the collection of documents and accounts he arranged in his old age. The parallelism of the chapters 2 and 7, 3 and 6, 4 and 5 indicates a late arrangement, as well as the end of the first chapter does:
'Now Daniel lived on until the first year of Cyrus the king.' - Daniel 1:21