Selecting Features

Should we exclude features like race and gender when building models ?
or does it depend on the use case?

It depends on the use case. Adding these features can allow you to understand what bias a predictive model can get. You can also enforce/protect a particular group during the learning phase: this is linked with fair learning (https://fairlearn.org/).