Why do inverter of a EV motor need capacitor?
No, it has nothing to do with correcting power factor.  The bus supplying the inverter is DC.

It's because there is substantial inductance and resistance between the battery and the switches that make up the 3 phase inverter, and if they were to switch without any capacitance on the local bus, there would be a substantial voltage drop and probably a lot of ringing due to the series inductance and parasitic capacitances.

This would cause EMI, issues with control of the motor, losses, extra stress on the switches, and probably other bad things I'm not thinking of off the top of my head.