Rav S. R. Hirsch clarifies that both the song and the teaching aspects of these instructions were given specifically for the benefit of Yehoshua, the future leader of the Jewish people. The manner through which information is conveyed affects the way it is absorbed, and songs and poems make it easier to see the beauty within the words. Once the proper medium of education is established, Yehoshua had to learn the way to teach. For knowledge to last, it is not enough to absorb information but to extract the spirit behind the letter of the Torah law and observe its beauty and brilliance.
By studying and examining the Torah, not only can we learn its laws, but we can also extract the beauty behind them, such that they sound like music, to us and to those we convey them to.