The job market is not as good in this current day and age as it used to be a couple of decades back. Often there are many more applicants for a job when it is announced. Therefore, not everyone is able to bag a job they apply for and there are some rejections that take place.
Letting someone know that they have been unable to get a job is tough. An email with some kind words is probably the best way to go about it. The email should be composed in a manner that it does not deflate the person receiving it.
In the first paragraph, appreciate the candidate for participating in the process of interview for the job and let them know that they have been unable to secure it.
In the second paragraph, let them know about the policies of the company and how it believes in providing equal opportunities to everyone without any discrimination.
In the closing paragraph, wish the candidate luck for future and hope that they have a long and successful career.