Malchus was not a soldier so much as an observer. A spy for his boss, really. His role was to return to Caiaphas and share who did what, how the arrest went, did Judas really betray him, etc. Even though Jesus knew these people hated Him and were arresting an innocent man, He showed compassion for Malchus and healed him. That is grace.