I believe the reason was this was toward the end of the occupation of Warsaw, Poland. The German officer was disillusioned with the war at that point. When he realized the great talent Szpilman was, he was unwilling to send him away to certain death or kill him as his orders probably dictated. He loved the talent more than he loved the war, the occupation, or his official duties. I am not sure if the German Officer knew who Szpilman was, but he definitely recognized the talent.
On Wikipedia, it talks of this encounter:
In November 1944, Szpilman was hiding out in an abandoned building at 223 Niepodległości Avenue when he was found by a German officer, Captain Wilm Hosenfeld. To Szpilman's surprise, the officer did not arrest or kill him; after discovering that the emaciated Szpilman was a pianist, Hosenfeld asked him to play something (a piano was on the ground floor). Szpilman played Chopin's Nocturne in C-sharp minor. After that, the officer showed Szpilman a better place to hide and brought him bread and jam on numerous occasions. He also offered Szpilman one of his coats to keep warm in the freezing temperatures. Szpilman did not know the name of the German officer until 1951. Despite the efforts of Szpilman and the Poles to rescue Hosenfeld, he died in a Soviet prisoner of war camp in 1952.
More information can be found at: http://www.szpilman.net/