If a mitzvah is done without kavanah, does it have to be repeated?
The halachah is that mitzvos tzrichos kavanah (mitzvos must be performed with the specific intention of fulfilling them), as opposed to k’misasek (going through the motions), or worse, doing the mitzvah with the wrong intention, for example, blowing shofar for music-making. A mitzvah that is done without kavanah should be repeated, although the brachah should not be recited again.
People may recite Shema in the morning and evening, for example, having in mind the mitzvah of reciting the Shema, but neglecting to have in mind the additional mitzvah of zechiras yetzias Mitzraim (mentioning the exodus from Egypt), which is fulfilled when saying the third paragraph of Shema. Some suggest that is the reason we repeat zechiras yetzias Mitzraim when saying the Sheish Zechiros (the Six Remembrances) after davening, in case one forgot to have kavanah earlier during Shema.
There are many poskim who argue that if it’s obvious from the context that it is being done for the purpose of performing a mitzvah—such as in shul during davening—there is no need to repeat it.
There’s a machlokes (difference of opinion) among poskim whether kavanah is necessary for mitzvos d’rabanan (rabbinic commandments), as it is for mitzvos d’oraisa (biblical commandments); in practice one should have kavanah when doing mitzvos d’rabanan, but there’s no need to repeat it if one wasn’t mindful while performing the mitzvah.