1. It gives them a kind of closure and treats them with respect.
2. It can help them improve for future applications.
Usually, the reason is not "Someone else is a better fit". We're not just trying to fill one position -- if we find good engineers, we'll hire them. Usually feedback is related to stuff that came up in either the coding project or the interview. It helps people in the same way that code review helps them: by giving them an opportunity to learn and improve.