Performance of the CMS High Granularity Calorimeter prototype to charged pion beams of 20$-$300 GeV/c