Can somebody explain how the harmony works in this piece?
There's is nothing to explain. The harmony is the result of the counterpoint of 2 contrary parts. This is a teaching example:
The goal of this interval study is to demonstrate - or to find out by the pupils themselves - which intervals we will become by starting of a certain pitch and two parts are playing in contrary movement. (As they are notated in octavas you can play them as well close together). And then notate the results you get:
start: unisono
1) one tone up and one down: 3rd
2) two tones up and two tones down: 5th
.
.
.
etc. you can complete the liste and also consider the specific intervals:
It seems that the right hand plays on C key and the left hand alternates between G and D.
I don't agree with this point and with other answers. Both hands are playing in C, while the 2nd phrase (i.e. the middle part measure 5-12) is in G.
Why when played in opposite direction do the intervals sound consonant?
- They are not all consonant. Why shouldn't they not be what they are? It's really senseful to write the intervals and also the relative names of doremi and memorize which pairs are consonant and which dissonant and listen to it by playing them very slowly.