What is the name and purpose of this part on the flap at the DA40?
It is an actuator fairing. It covers the flap actuator so to minimize the drag created by it.

An actuator directly exposed to the airflow would create more drag, increasing fuel consumption and reducing the flight range.